185
185
186
186
Keyword arguments:
187
187
188
+ *angle* = 0
189
+ The angle of the key arrow. Measured in degrees anti-clockwise from the
190
+ x-axis.
191
+
188
192
*coordinates* = [ 'axes' | 'figure' | 'data' | 'inches' ]
189
193
Coordinate system and units for *X*, *Y*: 'axes' and 'figure' are
190
194
normalized coordinate systems with 0,0 in the lower left and 1,1
@@ -236,6 +240,7 @@ def __init__(self, Q, X, Y, U, label, **kw):
236
240
self .X = X
237
241
self .Y = Y
238
242
self .U = U
243
+ self .angle = kw .pop ('angle' , 0 )
239
244
self .coord = kw .pop ('coordinates' , 'axes' )
240
245
self .color = kw .pop ('color' , None )
241
246
self .label = label
@@ -296,7 +301,8 @@ def _init(self):
296
301
_mask = self .Q .Umask
297
302
self .Q .Umask = ma .nomask
298
303
self .verts = self .Q ._make_verts (np .array ([self .U ]),
299
- np .zeros ((1 ,)))
304
+ np .zeros ((1 ,)),
305
+ self .angle )
300
306
self .Q .Umask = _mask
301
307
self .Q .pivot = _pivot
302
308
kw = self .Q .polykw
@@ -514,7 +520,7 @@ def _init(self):
514
520
515
521
# _make_verts sets self.scale if not already specified
516
522
if not self ._initialized and self .scale is None :
517
- self ._make_verts (self .U , self .V )
523
+ self ._make_verts (self .U , self .V , self . angles )
518
524
519
525
self ._initialized = True
520
526
@@ -530,7 +536,7 @@ def get_datalim(self, transData):
530
536
@allow_rasterization
531
537
def draw (self , renderer ):
532
538
self ._init ()
533
- verts = self ._make_verts (self .U , self .V )
539
+ verts = self ._make_verts (self .U , self .V , self . angles )
534
540
self .set_verts (verts , closed = False )
535
541
self ._new_UV = False
536
542
mcollections .PolyCollection .draw (self , renderer )
@@ -610,15 +616,15 @@ def _angles_lengths(self, U, V, eps=1):
610
616
lengths = np .hypot (* dxy .T ) / eps
611
617
return angles , lengths
612
618
613
- def _make_verts (self , U , V ):
619
+ def _make_verts (self , U , V , angles ):
614
620
uv = (U + V * 1j )
615
- str_angles = isinstance (self . angles , six .string_types )
616
- if str_angles and (self . angles == 'xy' and self .scale_units == 'xy' ):
621
+ str_angles = isinstance (angles , six .string_types )
622
+ if str_angles and (angles == 'xy' and self .scale_units == 'xy' ):
617
623
# Here eps is 1 so that if we get U, V by diffing
618
624
# the X, Y arrays, the vectors will connect the
619
625
# points, regardless of the axis scaling (including log).
620
626
angles , lengths = self ._angles_lengths (U , V , eps = 1 )
621
- elif str_angles and (self . angles == 'xy' or self .scale_units == 'xy' ):
627
+ elif str_angles and (angles == 'xy' or self .scale_units == 'xy' ):
622
628
# Calculate eps based on the extents of the plot
623
629
# so that we don't end up with roundoff error from
624
630
# adding a small number to a large.
@@ -651,12 +657,12 @@ def _make_verts(self, U, V):
651
657
self .scale = scale * widthu_per_lenu
652
658
length = a * (widthu_per_lenu / (self .scale * self .width ))
653
659
X , Y = self ._h_arrows (length )
654
- if str_angles and (self . angles == 'xy' ):
660
+ if str_angles and (angles == 'xy' ):
655
661
theta = angles
656
- elif str_angles and (self . angles == 'uv' ):
662
+ elif str_angles and (angles == 'uv' ):
657
663
theta = np .angle (uv )
658
664
else :
659
- theta = ma .masked_invalid (np .deg2rad (self . angles )).filled (0 )
665
+ theta = ma .masked_invalid (np .deg2rad (angles )).filled (0 )
660
666
theta = theta .reshape ((- 1 , 1 )) # for broadcasting
661
667
xy = (X + Y * 1j ) * np .exp (1j * theta ) * self .width
662
668
xy = xy [:, :, np .newaxis ]
0 commit comments