@@ -226,78 +226,86 @@ def R(a, r, w, h):
226
226
# according to the value of *textposition*. Usage of those arguments is shown
227
227
# below.
228
228
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 ()
233
230
fig .canvas .draw ()# Need to draw the figure to define renderer
231
+ ax .set_title ("AngleLabel example" )
234
232
235
- #### SUBPLOT 1 ####
236
233
# Plot two crossing lines and label each angle between them with the above
237
234
# ``AngleAnnotation`` tool.
238
235
center = (4.5 ,650 )
239
236
p1 = [(2.5 ,710 ), (6.0 ,605 )]
240
237
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" )
244
241
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$" )
249
246
250
247
251
248
# Showcase some styling options for the angle arc, as well as the text.
252
249
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$" ,
255
252
linestyle = "--" ,color = "gray" ,textposition = "outside" ,
256
253
text_kw = dict (fontsize = 16 ,color = "gray" ))
257
254
258
255
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
+
260
264
# Helper function to draw angle easily.
261
265
def plot_angle (ax ,pos ,angle ,length = 0.95 ,acol = "C0" ,** kwargs ):
262
266
vec2 = np .array ([np .cos (np .deg2rad (angle )),np .sin (np .deg2rad (angle ))])
263
267
xy = np .c_ [[length ,0 ], [0 ,0 ],vec2 * length ].T + np .array (pos )
264
268
ax .plot (* xy .T ,color = acol )
265
269
return AngleAnnotation (pos ,xy [0 ],xy [2 ],ax = ax ,** kwargs )
266
270
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
+
267
276
# Showcase different text positions.
277
+ ax1 .margins (y = 0.4 )
278
+ ax1 .set_title ("textposition" )
268
279
kw = dict (size = 75 ,unit = "points" ,text = r"$60°$" )
269
280
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" ,
273
284
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" ,
275
286
text_kw = dict (xytext = (30 ,20 ),arrowprops = dict (arrowstyle = "->" ,
276
287
connectionstyle = "arc3,rad=-0.2" )),** kw )
277
288
278
- ax2 .annotate ("textposition" ,xy = (.02 ,1 ),xycoords = "axes fraction" ,
279
- bbox = dict (boxstyle = "round" ,fc = "w" ),ha = "left" ,va = "center" )
280
289
for x ,text in zip ([2.0 ,3.5 ,5.0 ,6.5 ], ['"inside"' ,'"outside"' ,'"edge"' ,
281
290
'"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 (),
283
292
bbox = dict (boxstyle = "round" ,fc = "w" ),ha = "left" ,fontsize = 8 ,
284
293
annotation_clip = True )
285
294
286
- #### SUBPLOT 3 ####
287
295
# Showcase different size units. The effect of this can best be observed
288
296
# by interactively changing the figure size
297
+ ax2 .margins (y = 0.4 )
298
+ ax2 .set_title ("unit" )
289
299
kw = dict (text = r"$60°$" ,textposition = "outside" )
290
300
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 )
295
305
296
- ax3 .annotate ("unit" ,xy = (.02 ,1 ),xycoords = "axes fraction" ,
297
- bbox = dict (boxstyle = "round" ,fc = "w" ),ha = "left" ,va = "center" )
298
306
for x ,text in zip ([2.0 ,3.5 ,5.0 ,6.5 ], ['"pixels"' ,'"points"' ,
299
307
'"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 (),
301
309
bbox = dict (boxstyle = "round" ,fc = "w" ),ha = "left" ,fontsize = 8 ,
302
310
annotation_clip = True )
303
311