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

Commitecf51a5

Browse files
committed
Split angle annotation example figure in two.
1 parent363bc5e commitecf51a5

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

‎examples/text_labels_and_annotations/angle_annotation.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -226,78 +226,86 @@ def R(a, r, w, h):
226226
# according to the value of *textposition*. Usage of those arguments is shown
227227
# below.
228228

229-
fig, (ax1,ax2,ax3)=plt.subplots(nrows=3,sharex=True,figsize=(7,7),
230-
gridspec_kw=dict(height_ratios=(3,1,1)))
231-
ax2.margins(y=0.4)
232-
ax3.margins(y=0.4)
229+
fig,ax=plt.subplots()
233230
fig.canvas.draw()# Need to draw the figure to define renderer
231+
ax.set_title("AngleLabel example")
234232

235-
#### SUBPLOT 1 ####
236233
# Plot two crossing lines and label each angle between them with the above
237234
# ``AngleAnnotation`` tool.
238235
center= (4.5,650)
239236
p1= [(2.5,710), (6.0,605)]
240237
p2= [(3.0,275), (5.5,900)]
241-
line1,=ax1.plot(*zip(*p1))
242-
line2,=ax1.plot(*zip(*p2))
243-
point,=ax1.plot(*center,marker="o")
238+
line1,=ax.plot(*zip(*p1))
239+
line2,=ax.plot(*zip(*p2))
240+
point,=ax.plot(*center,marker="o")
244241

245-
am1=AngleAnnotation(center,p1[1],p2[1],ax=ax1,size=75,text=r"$\alpha$")
246-
am2=AngleAnnotation(center,p2[1],p1[0],ax=ax1,size=35,text=r"$\beta$")
247-
am3=AngleAnnotation(center,p1[0],p2[0],ax=ax1,size=75,text=r"$\gamma$")
248-
am4=AngleAnnotation(center,p2[0],p1[1],ax=ax1,size=35,text=r"$\theta$")
242+
am1=AngleAnnotation(center,p1[1],p2[1],ax=ax,size=75,text=r"$\alpha$")
243+
am2=AngleAnnotation(center,p2[1],p1[0],ax=ax,size=35,text=r"$\beta$")
244+
am3=AngleAnnotation(center,p1[0],p2[0],ax=ax,size=75,text=r"$\gamma$")
245+
am4=AngleAnnotation(center,p2[0],p1[1],ax=ax,size=35,text=r"$\theta$")
249246

250247

251248
# Showcase some styling options for the angle arc, as well as the text.
252249
p= [(6.0,400), (5.3,410), (5.6,300)]
253-
ax1.plot(*zip(*p))
254-
am5=AngleAnnotation(p[1],p[0],p[2],ax=ax1,size=40,text=r"$\Phi$",
250+
ax.plot(*zip(*p))
251+
am5=AngleAnnotation(p[1],p[0],p[2],ax=ax,size=40,text=r"$\Phi$",
255252
linestyle="--",color="gray",textposition="outside",
256253
text_kw=dict(fontsize=16,color="gray"))
257254

258255

259-
#### SUBPLOT 2 ####
256+
#########################################################################
257+
# ``AngleLabel`` options
258+
# ~~~~~~~~~~~~~~~~~~~~~~
259+
#
260+
# The *textposition* and *unit* keyword arguments may be used to modify the
261+
# location of the text label, as shown below:
262+
263+
260264
# Helper function to draw angle easily.
261265
defplot_angle(ax,pos,angle,length=0.95,acol="C0",**kwargs):
262266
vec2=np.array([np.cos(np.deg2rad(angle)),np.sin(np.deg2rad(angle))])
263267
xy=np.c_[[length,0], [0,0],vec2*length].T+np.array(pos)
264268
ax.plot(*xy.T,color=acol)
265269
returnAngleAnnotation(pos,xy[0],xy[2],ax=ax,**kwargs)
266270

271+
272+
fig, (ax1,ax2)=plt.subplots(nrows=2,sharex=True)
273+
fig.suptitle("AngleLabel keyword arguments")
274+
fig.canvas.draw()# Need to draw the figure to define renderer
275+
267276
# Showcase different text positions.
277+
ax1.margins(y=0.4)
278+
ax1.set_title("textposition")
268279
kw=dict(size=75,unit="points",text=r"$60°$")
269280

270-
am6=plot_angle(ax2, (2.0,0),60,textposition="inside",**kw)
271-
am7=plot_angle(ax2, (3.5,0),60,textposition="outside",**kw)
272-
am8=plot_angle(ax2, (5.0,0),60,textposition="edge",
281+
am6=plot_angle(ax1, (2.0,0),60,textposition="inside",**kw)
282+
am7=plot_angle(ax1, (3.5,0),60,textposition="outside",**kw)
283+
am8=plot_angle(ax1, (5.0,0),60,textposition="edge",
273284
text_kw=dict(bbox=dict(boxstyle="round",fc="w")),**kw)
274-
am9=plot_angle(ax2, (6.5,0),60,textposition="edge",
285+
am9=plot_angle(ax1, (6.5,0),60,textposition="edge",
275286
text_kw=dict(xytext=(30,20),arrowprops=dict(arrowstyle="->",
276287
connectionstyle="arc3,rad=-0.2")),**kw)
277288

278-
ax2.annotate("textposition",xy=(.02,1),xycoords="axes fraction",
279-
bbox=dict(boxstyle="round",fc="w"),ha="left",va="center")
280289
forx,textinzip([2.0,3.5,5.0,6.5], ['"inside"','"outside"','"edge"',
281290
'"edge", custom arrow']):
282-
ax2.annotate(text,xy=(x,0),xycoords=ax2.get_xaxis_transform(),
291+
ax1.annotate(text,xy=(x,0),xycoords=ax1.get_xaxis_transform(),
283292
bbox=dict(boxstyle="round",fc="w"),ha="left",fontsize=8,
284293
annotation_clip=True)
285294

286-
#### SUBPLOT 3 ####
287295
# Showcase different size units. The effect of this can best be observed
288296
# by interactively changing the figure size
297+
ax2.margins(y=0.4)
298+
ax2.set_title("unit")
289299
kw=dict(text=r"$60°$",textposition="outside")
290300

291-
am10=plot_angle(ax3, (2.0,0),60,size=50,unit="pixels",**kw)
292-
am11=plot_angle(ax3, (3.5,0),60,size=50,unit="points",**kw)
293-
am12=plot_angle(ax3, (5.0,0),60,size=0.25,unit="axes min",**kw)
294-
am13=plot_angle(ax3, (6.5,0),60,size=0.25,unit="axes max",**kw)
301+
am10=plot_angle(ax2, (2.0,0),60,size=50,unit="pixels",**kw)
302+
am11=plot_angle(ax2, (3.5,0),60,size=50,unit="points",**kw)
303+
am12=plot_angle(ax2, (5.0,0),60,size=0.25,unit="axes min",**kw)
304+
am13=plot_angle(ax2, (6.5,0),60,size=0.25,unit="axes max",**kw)
295305

296-
ax3.annotate("unit",xy=(.02,1),xycoords="axes fraction",
297-
bbox=dict(boxstyle="round",fc="w"),ha="left",va="center")
298306
forx,textinzip([2.0,3.5,5.0,6.5], ['"pixels"','"points"',
299307
'"axes min"','"axes max"']):
300-
ax3.annotate(text,xy=(x,0),xycoords=ax3.get_xaxis_transform(),
308+
ax2.annotate(text,xy=(x,0),xycoords=ax2.get_xaxis_transform(),
301309
bbox=dict(boxstyle="round",fc="w"),ha="left",fontsize=8,
302310
annotation_clip=True)
303311

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp