Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf15aeee

Browse files
authored
Updated Angles on Bracket arrow styles example to make angles clear#23176 (#24145)
* removed AngleAnnotation from angle_on_bracket_arrow example* Fixes indentation mistake.* rebase to main, remove conflicting commit
1 parent42fdbea commitf15aeee

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
===================================
3+
Angle annotations on bracket arrows
4+
===================================
5+
6+
This example shows how to add angle annotations to bracket arrow styles
7+
created using `.FancyArrowPatch`. *angleA* and *angleB* are measured from a
8+
vertical line as positive (to the left) or negative (to the right). Blue
9+
`.FancyArrowPatch` arrows indicate the directions of *angleA* and *angleB*
10+
from the vertical and axes text annotate the angle sizes.
11+
"""
12+
13+
importmatplotlib.pyplotasplt
14+
importnumpyasnp
15+
frommatplotlib.patchesimportFancyArrowPatch
16+
17+
18+
defget_point_of_rotated_vertical(origin,line_length,degrees):
19+
"""Return xy coordinates of the vertical line end rotated by degrees."""
20+
rad=np.deg2rad(-degrees)
21+
return [origin[0]+line_length*np.sin(rad),
22+
origin[1]+line_length*np.cos(rad)]
23+
24+
25+
fig,ax=plt.subplots(figsize=(8,7))
26+
ax.set(xlim=(0,6),ylim=(-1,4))
27+
ax.set_title("Orientation of the bracket arrows relative to angleA and angleB")
28+
29+
fori,styleinenumerate(["]-[","|-|"]):
30+
forj,angleinenumerate([-40,60]):
31+
y=2*i+j
32+
arrow_centers= ((1,y), (5,y))
33+
vlines= ((1,y+0.5), (5,y+0.5))
34+
anglesAB= (angle,-angle)
35+
bracketstyle=f"{style}, angleA={anglesAB[0]}, angleB={anglesAB[1]}"
36+
bracket=FancyArrowPatch(*arrow_centers,arrowstyle=bracketstyle,
37+
mutation_scale=42)
38+
ax.add_patch(bracket)
39+
ax.text(3,y+0.05,bracketstyle,ha="center",va="bottom")
40+
ax.vlines([i[0]foriinvlines], [y,y], [i[1]foriinvlines],
41+
linestyles="--",color="C0")
42+
# Get the top coordinates for the drawn patches at A and B
43+
patch_tops= [get_point_of_rotated_vertical(center,0.5,angle)
44+
forcenter,angleinzip(arrow_centers,anglesAB)]
45+
# Define the connection directions for the annotation arrows
46+
connection_dirs= (1,-1)ifangle>0else (-1,1)
47+
# Add arrows and annotation text
48+
arrowstyle="Simple, tail_width=0.5, head_width=4, head_length=8"
49+
forvline,dir,patch_top,angleinzip(vlines,connection_dirs,
50+
patch_tops,anglesAB):
51+
kw=dict(connectionstyle=f"arc3,rad={dir*0.5}",
52+
arrowstyle=arrowstyle,color="C0")
53+
ax.add_patch(FancyArrowPatch(vline,patch_top,**kw))
54+
ax.text(vline[0]-dir*0.15,y+0.3,f'{angle}°',ha="center",
55+
va="center")
56+
57+
#############################################################################
58+
#
59+
# .. admonition:: References
60+
#
61+
# The use of the following functions, methods, classes and modules is shown
62+
# in this example:
63+
#
64+
# - `matplotlib.patches.ArrowStyle`

‎lib/matplotlib/patches.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,14 @@ class ArrowStyle(_Style):
31193119
stroked. This is meant to be used to correct the location of the
31203120
head so that it does not overshoot the destination point, but not all
31213121
classes support it.
3122+
3123+
Notes
3124+
-----
3125+
*angleA* and *angleB* specify the orientation of the bracket, as either a
3126+
clockwise or counterclockwise angle depending on the arrow type. 0 degrees
3127+
means perpendicular to the line connecting the arrow's head and tail.
3128+
3129+
.. plot:: gallery/text_labels_and_annotations/angles_on_bracket_arrows.py
31223130
"""
31233131

31243132
_style_list= {}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp