Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Curve ArrowStyle docs #25372

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,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 @@ -3197,29 +3197,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