diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index d6a25dfc487c..935e8f8d6ad2 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -2372,14 +2372,19 @@ def __call__(self, x0, y0, width, height, mutation_size): class LArrow: """A box in the shape of a left-pointing arrow.""" - def __init__(self, pad=0.3): + def __init__(self, pad=0.3, fhead=False): """ Parameters ---------- pad : float, default: 0.3 The amount of padding around the original box. + + fhead : bool, default: False + If the arrowheads should be flush with the top + and botton sides of the arrow body. """ self.pad = pad + self.fhead = fhead def __call__(self, x0, y0, width, height, mutation_size): # padding @@ -2394,11 +2399,17 @@ def __call__(self, x0, y0, width, height, mutation_size): dxx = dx / 2 x0 = x0 + pad / 1.4 # adjust by ~sqrt(2) - return Path._create_closed( - [(x0 + dxx, y0), (x1, y0), (x1, y1), (x0 + dxx, y1), - (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), - (x0 + dxx, y0 - dxx), # arrow - (x0 + dxx, y0)]) + if self.fhead: + return Path._create_closed([(x0 + dxx - pad, y0), (x1, y0), + (x1, y1), (x0 + dxx - pad, y1), + (x0 - dx - pad, y0 + dx), + (x0 + dxx - pad, y0)]) + + return Path._create_closed([(x0 + dxx, y0), (x1, y0), (x1, y1), + (x0 + dxx, y1), (x0 + dxx, y1 + dxx), + (x0 - dx, y0 + dx), + (x0 + dxx, y0 - dxx), # arrow + (x0 + dxx, y0), (x0 + dxx, y0)]) @_register_style(_style_list) class RArrow(LArrow): @@ -2415,14 +2426,19 @@ class DArrow: """A box in the shape of a two-way arrow.""" # Modified from LArrow to add a right arrow to the bbox. - def __init__(self, pad=0.3): + def __init__(self, pad=0.3, fhead=False): """ Parameters ---------- pad : float, default: 0.3 The amount of padding around the original box. + + fhead : bool, default: False + If the arrowheads should be flush with the top + and botton sides of the arrow body. """ self.pad = pad + self.fhead = fhead def __call__(self, x0, y0, width, height, mutation_size): # padding @@ -2438,14 +2454,24 @@ def __call__(self, x0, y0, width, height, mutation_size): dxx = dx / 2 x0 = x0 + pad / 1.4 # adjust by ~sqrt(2) - return Path._create_closed([ - (x0 + dxx, y0), (x1, y0), # bot-segment - (x1, y0 - dxx), (x1 + dx + dxx, y0 + dx), - (x1, y1 + dxx), # right-arrow - (x1, y1), (x0 + dxx, y1), # top-segment - (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), - (x0 + dxx, y0 - dxx), # left-arrow - (x0 + dxx, y0)]) + if self.fhead: + return Path._create_closed([(x0 + dxx - pad, y0), + (x1 + pad, y0), + (x1 + dx + dxx + pad, y0 + dx), + (x1 + pad, y1), + (x0 + dxx - pad, y1), + (x0 - dx - pad, y0 + dx), + (x0 + dxx - pad, y0)]) + + return Path._create_closed([(x0 + dxx, y0), (x1, y0), + (x1, y0 - dxx), + (x1 + dx + dxx, y0 + dx), + (x1, y1 + dxx), # right-arrow + (x1, y1), (x0 + dxx, y1), + (x0 + dxx, y1 + dxx), + (x0 - dx, y0 + dx), + (x0 + dxx, y0 - dxx), # left-arrow + (x0 + dxx, y0)]) @_register_style(_style_list) class Round: diff --git a/tutorials/text/annotations.py b/tutorials/text/annotations.py index bee2e244238d..90bc5796a83a 100644 --- a/tutorials/text/annotations.py +++ b/tutorials/text/annotations.py @@ -192,10 +192,10 @@ # Class Name Attrs # ========== ============== ========================== # Circle ``circle`` pad=0.3 -# DArrow ``darrow`` pad=0.3 +# DArrow ``darrow`` pad=0.3,fhead=False # Ellipse ``ellipse`` pad=0.3 -# LArrow ``larrow`` pad=0.3 -# RArrow ``rarrow`` pad=0.3 +# LArrow ``larrow`` pad=0.3,fhead=False +# RArrow ``rarrow`` pad=0.3,fhead=False # Round ``round`` pad=0.3,rounding_size=None # Round4 ``round4`` pad=0.3,rounding_size=None # Roundtooth ``roundtooth`` pad=0.3,tooth_size=None @@ -215,12 +215,12 @@ # (facecolor, edgewidth, etc.) can be accessed and modified as usual. # `.FancyBboxPatch.set_boxstyle` sets the box shape:: # -# bb.set_boxstyle("rarrow", pad=0.6) +# bb.set_boxstyle("rarrow", pad=0.6, fhead=True) # # The attribute arguments can also be specified within the style # name with separating comma:: # -# bb.set_boxstyle("rarrow, pad=0.6") +# bb.set_boxstyle("rarrow, pad=0.6, fhead=True") # # # Defining custom box styles