Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf5bd76

Browse files
committed
Clean up Curve ArrowStyle docs
By combining A/B parameters, to match the style of the CurveBracket, CurveFilled, etc. Also, tweak the example image so that it is not scaled down in the docs, and explicitly shows 0°.
1 parent 447c0c8 commit bf5bd76

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

galleries/examples/text_labels_and_annotations/angles_on_bracket_arrows.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,39 @@ def get_point_of_rotated_vertical(origin, line_length, degrees):
2323
origin[1] + line_length * np.cos(rad)]
2424

2525

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

30-
for i, style in enumerate(["]-[", "|-|"]):
31-
for j, angle in enumerate([-40, 60]):
32-
y = 2*i + j
33-
arrow_centers = ((1, y), (5, y))
34-
vlines = ((1, y + 0.5), (5, y + 0.5))
35-
anglesAB = (angle, -angle)
36-
bracketstyle = f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
37-
bracket = FancyArrowPatch(*arrow_centers, arrowstyle=bracketstyle,
38-
mutation_scale=42)
39-
ax.add_patch(bracket)
40-
ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom")
41-
ax.vlines([i[0] for i in vlines], [y, y], [i[1] for i in vlines],
42-
linestyles="--", color="C0")
43-
# Get the top coordinates for the drawn patches at A and B
44-
patch_tops = [get_point_of_rotated_vertical(center, 0.5, angle)
45-
for center, angle in zip(arrow_centers, anglesAB)]
46-
# Define the connection directions for the annotation arrows
47-
connection_dirs = (1, -1) if angle > 0 else (-1, 1)
48-
# Add arrows and annotation text
49-
arrowstyle = "Simple, tail_width=0.5, head_width=4, head_length=8"
50-
for vline, dir, patch_top, angle in zip(vlines, connection_dirs,
51-
patch_tops, anglesAB):
52-
kw = dict(connectionstyle=f"arc3,rad={dir * 0.5}",
53-
arrowstyle=arrowstyle, color="C0")
54-
ax.add_patch(FancyArrowPatch(vline, patch_top, **kw))
55-
ax.text(vline[0] - dir * 0.15, y + 0.3, f'{angle}°', ha="center",
56-
va="center")
30+
style = ']-['
31+
for i, angle in enumerate([-40, 0, 60]):
32+
y = 2*i
33+
arrow_centers = ((1, y), (5, y))
34+
vlines = ((1, y + 0.5), (5, y + 0.5))
35+
anglesAB = (angle, -angle)
36+
bracketstyle = f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
37+
bracket = FancyArrowPatch(*arrow_centers, arrowstyle=bracketstyle,
38+
mutation_scale=42)
39+
ax.add_patch(bracket)
40+
ax.text(3, y + 0.05, bracketstyle, ha="center", va="bottom", fontsize=14)
41+
ax.vlines([line[0] for line in vlines], [y, y], [line[1] for line in vlines],
42+
linestyles="--", color="C0")
43+
# Get the top coordinates for the drawn patches at A and B
44+
patch_tops = [get_point_of_rotated_vertical(center, 0.5, angle)
45+
for center, angle in zip(arrow_centers, anglesAB)]
46+
# Define the connection directions for the annotation arrows
47+
connection_dirs = (1, -1) if angle > 0 else (-1, 1)
48+
# Add arrows and annotation text
49+
arrowstyle = "Simple, tail_width=0.5, head_width=4, head_length=8"
50+
for vline, dir, patch_top, angle in zip(vlines, connection_dirs,
51+
patch_tops, anglesAB):
52+
kw = dict(connectionstyle=f"arc3,rad={dir * 0.5}",
53+
arrowstyle=arrowstyle, color="C0")
54+
ax.add_patch(FancyArrowPatch(vline, patch_top, **kw))
55+
ax.text(vline[0] - dir * 0.15, y + 0.7, f'{angle}°', ha="center",
56+
va="center")
57+
58+
plt.show()
5759

5860
# %%
5961
#

lib/matplotlib/patches.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,29 +3197,18 @@ def __init__(self, head_length=.4, head_width=.2, widthA=1., widthB=1.,
31973197
Parameters
31983198
----------
31993199
head_length : float, default: 0.4
3200-
Length of the arrow head, relative to *mutation_scale*.
3200+
Length of the arrow head, relative to *mutation_size*.
32013201
head_width : float, default: 0.2
3202-
Width of the arrow head, relative to *mutation_scale*.
3203-
widthA : float, default: 1.0
3204-
Width of the bracket at the beginning of the arrow
3205-
widthB : float, default: 1.0
3206-
Width of the bracket at the end of the arrow
3207-
lengthA : float, default: 0.2
3208-
Length of the bracket at the beginning of the arrow
3209-
lengthB : float, default: 0.2
3210-
Length of the bracket at the end of the arrow
3211-
angleA : float, default 0
3212-
Orientation of the bracket at the beginning, as a
3213-
counterclockwise angle. 0 degrees means perpendicular
3214-
to the line.
3215-
angleB : float, default 0
3216-
Orientation of the bracket at the beginning, as a
3217-
counterclockwise angle. 0 degrees means perpendicular
3218-
to the line.
3219-
scaleA : float, default *mutation_size*
3220-
The mutation_size for the beginning bracket
3221-
scaleB : float, default *mutation_size*
3222-
The mutation_size for the end bracket
3202+
Width of the arrow head, relative to *mutation_size*.
3203+
widthA, widthB : float, default: 1.0
3204+
Width of the bracket.
3205+
lengthA, lengthB : float, default: 0.2
3206+
Length of the bracket.
3207+
angleA, angleB : float, default: 0
3208+
Orientation of the bracket, as a counterclockwise angle.
3209+
0 degrees means perpendicular to the line.
3210+
scaleA, scaleB : float, default: *mutation_size*
3211+
The scale of the brackets.
32233212
"""
32243213

32253214
self.head_length, self.head_width = head_length, head_width

0 commit comments

Comments
 (0)