1
1
"""
2
- ============================
3
- Scale invariant anglemarker
4
- ============================
2
+ ===========================
3
+ Scale invariant anglelabel
4
+ ===========================
5
5
6
6
This example shows how to create a scale invariant angle marker. It is often
7
7
useful to mark angles between lines or inside shapes with a circular arc. While
14
14
15
15
This calls for a solution where the arc's center is defined in data space, but
16
16
its radius in a physical unit like points or pixels, or as a ratio of the Axes
17
- dimension. The following ``AngleMarker `` class provides such solution.
17
+ dimension. The following ``AngleAnnotation `` class provides such solution.
18
18
19
19
The example below serves two purposes:
20
20
29
29
"""
30
30
31
31
#########################################################################
32
- #AngleMarker class
33
- # ~~~~~~~~~~~~~~~~~
32
+ #AngleAnnotation class
33
+ # ~~~~~~~~~~~~~~~~~~~~~
34
34
# The essential idea here is to subclass `~.patches.Arc` and set its transform
35
35
# to the `~.transforms.IdentityTransform`, making the parameters of the arc
36
36
# defined in pixel space.
64
64
from matplotlib .transforms import IdentityTransform ,TransformedBbox ,Bbox
65
65
66
66
67
- class AngleMarker (Arc ):
67
+ class AngleAnnotation (Arc ):
68
68
"""
69
69
Draws an arc between two vectors which appears circular in display space.
70
70
"""
@@ -218,9 +218,9 @@ def R(a, r, w, h):
218
218
# Usage
219
219
# ~~~~~
220
220
#
221
- # Required arguments to ``AngleMarker `` are the center of the arc, *xy*, and
222
- # two points, such that the arc spans between the two vectors connecting *p1*
223
- # and *p2* with *xy*, respectively. Those are given in data coordinates.
221
+ # Required arguments to ``AngleAnnotation `` are the center of the arc, *xy*,
222
+ #and two points, such that the arc spans between the two vectors connecting
223
+ #*p1* and *p2* with *xy*, respectively. Those are given in data coordinates.
224
224
# Further arguments are the *size* of the arc and its *unit*. Additionally, a
225
225
# *text* can be specified, that will be drawn either in- or outside of the arc,
226
226
# according to the value of *textposition*. Usage of those arguments is shown
@@ -233,27 +233,27 @@ def R(a, r, w, h):
233
233
fig .canvas .draw ()# Need to draw the figure to define renderer
234
234
235
235
#### SUBPLOT 1 ####
236
- # Plot two crossing lines and label each angle between them with the
237
- #above `AngleMarker` tool.
236
+ # Plot two crossing lines and label each angle between them with the above
237
+ #``AngleAnnotation`` tool.
238
238
center = (4.5 ,650 )
239
239
p1 = [(2.5 ,710 ), (6.0 ,605 )]
240
240
p2 = [(3.0 ,275 ), (5.5 ,900 )]
241
241
line1 ,= ax1 .plot (* zip (* p1 ))
242
242
line2 ,= ax1 .plot (* zip (* p2 ))
243
243
point ,= ax1 .plot (* center ,marker = "o" )
244
244
245
- am1 = AngleMarker (center ,p1 [1 ],p2 [1 ],ax = ax1 ,size = 75 ,text = r"$\alpha$" )
246
- am2 = AngleMarker (center ,p2 [1 ],p1 [0 ],ax = ax1 ,size = 35 ,text = r"$\beta$" )
247
- am3 = AngleMarker (center ,p1 [0 ],p2 [0 ],ax = ax1 ,size = 75 ,text = r"$\gamma$" )
248
- am4 = AngleMarker (center ,p2 [0 ],p1 [1 ],ax = ax1 ,size = 35 ,text = r"$\theta$" )
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$" )
249
249
250
250
251
251
# Showcase some styling options for the angle arc, as well as the text.
252
252
p = [(6.0 ,400 ), (5.3 ,410 ), (5.6 ,300 )]
253
253
ax1 .plot (* zip (* p ))
254
- am5 = AngleMarker (p [1 ],p [0 ],p [2 ],ax = ax1 ,size = 40 ,text = r"$\Phi$" ,
255
- linestyle = "--" ,color = "gray" ,textposition = "outside" ,
256
- text_kw = dict (fontsize = 16 ,color = "gray" ))
254
+ am5 = AngleAnnotation (p [1 ],p [0 ],p [2 ],ax = ax1 ,size = 40 ,text = r"$\Phi$" ,
255
+ linestyle = "--" ,color = "gray" ,textposition = "outside" ,
256
+ text_kw = dict (fontsize = 16 ,color = "gray" ))
257
257
258
258
259
259
#### SUBPLOT 2 ####
@@ -262,7 +262,7 @@ def plot_angle(ax, pos, angle, length=0.95, acol="C0", **kwargs):
262
262
vec2 = np .array ([np .cos (np .deg2rad (angle )),np .sin (np .deg2rad (angle ))])
263
263
xy = np .c_ [[length ,0 ], [0 ,0 ],vec2 * length ].T + np .array (pos )
264
264
ax .plot (* xy .T ,color = acol )
265
- return AngleMarker (pos ,xy [0 ],xy [2 ],ax = ax ,** kwargs )
265
+ return AngleAnnotation (pos ,xy [0 ],xy [2 ],ax = ax ,** kwargs )
266
266
267
267
# Showcase different text positions.
268
268
kw = dict (size = 75 ,unit = "points" ,text = r"$60°$" )