Skip to content

Commit

Permalink
Merge pull request #25377 from meeseeksmachine/auto-backport-of-pr-25…
Browse files Browse the repository at this point in the history
…372-on-v3.7.x
  • Loading branch information
ksunden committed Mar 3, 2023
2 parents 5908554 + 11c6af2 commit 66232bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 51 deletions.
60 changes: 31 additions & 29 deletions examples/text_labels_and_annotations/angles_on_bracket_arrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,39 @@ def get_point_of_rotated_vertical(origin, line_length, degrees):
origin[1] + line_length * np.cos(rad)]


fig, ax = plt.subplots(figsize=(8, 7))
ax.set(xlim=(0, 6), ylim=(-1, 4))
fig, ax = plt.subplots()
ax.set(xlim=(0, 6), ylim=(-1, 5))
ax.set_title("Orientation of the bracket arrows relative to angleA and angleB")

for i, style in enumerate(["]-[", "|-|"]):
for j, angle in enumerate([-40, 60]):
y = 2*i + j
arrow_centers = ((1, y), (5, y))
vlines = ((1, y + 0.5), (5, y + 0.5))
anglesAB = (angle, -angle)
bracketstyle = f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
bracket = FancyArrowPatch(*arrow_centers, arrowstyle=bracketstyle,
mutation_scale=42)
ax.add_patch(bracket)
ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom")
ax.vlines([i[0] for i in vlines], [y, y], [i[1] for i in vlines],
linestyles="--", color="C0")
# Get the top coordinates for the drawn patches at A and B
patch_tops = [get_point_of_rotated_vertical(center, 0.5, angle)
for center, angle in zip(arrow_centers, anglesAB)]
# Define the connection directions for the annotation arrows
connection_dirs = (1, -1) if angle > 0 else (-1, 1)
# Add arrows and annotation text
arrowstyle = "Simple, tail_width=0.5, head_width=4, head_length=8"
for vline, dir, patch_top, angle in zip(vlines, connection_dirs,
patch_tops, anglesAB):
kw = dict(connectionstyle=f"arc3,rad={dir * 0.5}",
arrowstyle=arrowstyle, color="C0")
ax.add_patch(FancyArrowPatch(vline, patch_top, **kw))
ax.text(vline[0] - dir * 0.15, y + 0.3, f'{angle}°', ha="center",
va="center")
style = ']-['
for i, angle in enumerate([-40, 0, 60]):
y = 2*i
arrow_centers = ((1, y), (5, y))
vlines = ((1, y + 0.5), (5, y + 0.5))
anglesAB = (angle, -angle)
bracketstyle = f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
bracket = FancyArrowPatch(*arrow_centers, arrowstyle=bracketstyle,
mutation_scale=42)
ax.add_patch(bracket)
ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom", fontsize=14)
ax.vlines([line[0] for line in vlines], [y, y], [line[1] for line in vlines],
linestyles="--", color="C0")
# Get the top coordinates for the drawn patches at A and B
patch_tops = [get_point_of_rotated_vertical(center, 0.5, angle)
for center, angle in zip(arrow_centers, anglesAB)]
# Define the connection directions for the annotation arrows
connection_dirs = (1, -1) if angle > 0 else (-1, 1)
# Add arrows and annotation text
arrowstyle = "Simple, tail_width=0.5, head_width=4, head_length=8"
for vline, dir, patch_top, angle in zip(vlines, connection_dirs,
patch_tops, anglesAB):
kw = dict(connectionstyle=f"arc3,rad={dir * 0.5}",
arrowstyle=arrowstyle, color="C0")
ax.add_patch(FancyArrowPatch(vline, patch_top, **kw))
ax.text(vline[0] - dir * 0.15, y + 0.7, f'{angle}°', ha="center",
va="center")

plt.show()

#############################################################################
#
Expand Down
33 changes: 11 additions & 22 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3196,29 +3196,18 @@ def __init__(self, head_length=.4, head_width=.2, widthA=1., widthB=1.,
Parameters
----------
head_length : float, default: 0.4
Length of the arrow head, relative to *mutation_scale*.
Length of the arrow head, relative to *mutation_size*.
head_width : float, default: 0.2
Width of the arrow head, relative to *mutation_scale*.
widthA : float, default: 1.0
Width of the bracket at the beginning of the arrow
widthB : float, default: 1.0
Width of the bracket at the end of the arrow
lengthA : float, default: 0.2
Length of the bracket at the beginning of the arrow
lengthB : float, default: 0.2
Length of the bracket at the end of the arrow
angleA : float, default 0
Orientation of the bracket at the beginning, as a
counterclockwise angle. 0 degrees means perpendicular
to the line.
angleB : float, default 0
Orientation of the bracket at the beginning, as a
counterclockwise angle. 0 degrees means perpendicular
to the line.
scaleA : float, default *mutation_size*
The mutation_size for the beginning bracket
scaleB : float, default *mutation_size*
The mutation_size for the end bracket
Width of the arrow head, relative to *mutation_size*.
widthA, widthB : float, default: 1.0
Width of the bracket.
lengthA, lengthB : float, default: 0.2
Length of the bracket.
angleA, angleB : float, default: 0
Orientation of the bracket, as a counterclockwise angle.
0 degrees means perpendicular to the line.
scaleA, scaleB : float, default: *mutation_size*
The scale of the brackets.
"""

self.head_length, self.head_width = head_length, head_width
Expand Down

0 comments on commit 66232bc

Please sign in to comment.