136
136
is less than this, plot a dot (hexagon) of this diameter instead.
137
137
Default is 1.
138
138
139
- *pivot*: [ 'tail' | 'middle' | 'tip' ]
139
+ *pivot*: [ 'tail' | 'mid' | ' middle' | 'tip' ]
140
140
The part of the arrow that is at the grid point; the arrow rotates
141
141
about this point, hence the name *pivot*.
142
142
@@ -247,8 +247,9 @@ def on_dpi_change(fig):
247
247
if self_weakref is not None :
248
248
self_weakref .labelsep = (self_weakref ._labelsep_inches * fig .dpi )
249
249
self_weakref ._initialized = False # simple brute force update
250
- # works because _init is called
251
- # at the start of draw.
250
+ # works because _init is
251
+ # called at the start of
252
+ # draw.
252
253
253
254
self ._cid = Q .ax .figure .callbacks .connect ('dpi_changed' ,
254
255
on_dpi_change )
@@ -258,7 +259,7 @@ def on_dpi_change(fig):
258
259
self .fontproperties = kw .pop ('fontproperties' , dict ())
259
260
self .kw = kw
260
261
_fp = self .fontproperties
261
- #boxprops = dict(facecolor='red')
262
+ # boxprops = dict(facecolor='red')
262
263
self .text = mtext .Text (
263
264
text = label , # bbox=boxprops,
264
265
horizontalalignment = self .halign [self .labelpos ],
@@ -405,6 +406,8 @@ class Quiver(mcollections.PolyCollection):
405
406
in the draw() method.
406
407
"""
407
408
409
+ _PIVOT_VALS = ('tail' , 'mid' , 'middle' , 'tip' )
410
+
408
411
@docstring .Substitution (_quiver_doc )
409
412
def __init__ (self , ax , * args , ** kw ):
410
413
"""
@@ -430,7 +433,18 @@ def __init__(self, ax, *args, **kw):
430
433
self .angles = kw .pop ('angles' , 'uv' )
431
434
self .width = kw .pop ('width' , None )
432
435
self .color = kw .pop ('color' , 'k' )
433
- self .pivot = kw .pop ('pivot' , 'tail' )
436
+
437
+ pivot = kw .pop ('pivot' , 'tail' ).lower ()
438
+ # validate pivot
439
+ if pivot not in self ._PIVOT_VALS :
440
+ raise ValueError (
441
+ 'pivot must be one of {keys}, you passed {inp}' .format (
442
+ keys = self ._PIVOT_VALS , inp = pivot ))
443
+ # normalize to 'middle'
444
+ if pivot == 'mid' :
445
+ pivot = 'middle'
446
+ self .pivot = pivot
447
+
434
448
self .transform = kw .pop ('transform' , ax .transData )
435
449
kw .setdefault ('facecolors' , self .color )
436
450
kw .setdefault ('linewidths' , (0 ,))
@@ -452,10 +466,11 @@ def on_dpi_change(fig):
452
466
self_weakref = weak_self ()
453
467
if self_weakref is not None :
454
468
self_weakref ._new_UV = True # vertices depend on width, span
455
- # which in turn depend on dpi
469
+ # which in turn depend on dpi
456
470
self_weakref ._initialized = False # simple brute force update
457
- # works because _init is called
458
- # at the start of draw.
471
+ # works because _init is
472
+ # called at the start of
473
+ # draw.
459
474
460
475
self ._cid = self .ax .figure .callbacks .connect ('dpi_changed' ,
461
476
on_dpi_change )
@@ -654,7 +669,7 @@ def _h_arrows(self, length):
654
669
length = length .reshape (N , 1 )
655
670
# This number is chosen based on when pixel values overflow in Agg
656
671
# causing rendering errors
657
- #length = np.minimum(length, 2 ** 16)
672
+ # length = np.minimum(length, 2 ** 16)
658
673
np .clip (length , 0 , 2 ** 16 , out = length )
659
674
# x, y: normal horizontal arrow
660
675
x = np .array ([0 , - self .headaxislength ,
@@ -681,9 +696,9 @@ def _h_arrows(self, length):
681
696
# Now select X0, Y0 if short, otherwise X, Y
682
697
cbook ._putmask (X , short , X0 )
683
698
cbook ._putmask (Y , short , Y0 )
684
- if self .pivot [: 3 ] == 'mid ' :
699
+ if self .pivot == 'middle ' :
685
700
X -= 0.5 * X [:, 3 , np .newaxis ]
686
- elif self .pivot [: 3 ] == 'tip' :
701
+ elif self .pivot == 'tip' :
687
702
X = X - X [:, 3 , np .newaxis ] # numpy bug? using -= does not
688
703
# work here unless we multiply
689
704
# by a float first, as with 'mid'.
@@ -857,9 +872,9 @@ class Barbs(mcollections.PolyCollection):
857
872
From there :meth:`_make_barbs` is used to find the vertices of the
858
873
polygon to represent the barb based on this information.
859
874
'''
860
- #This may be an abuse of polygons here to render what is essentially maybe
861
- #1 triangle and a series of lines. It works fine as far as I can tell
862
- #however.
875
+ # This may be an abuse of polygons here to render what is essentially maybe
876
+ # 1 triangle and a series of lines. It works fine as far as I can tell
877
+ # however.
863
878
@docstring .interpd
864
879
def __init__ (self , ax , * args , ** kw ):
865
880
"""
@@ -879,30 +894,31 @@ def __init__(self, ax, *args, **kw):
879
894
self .flip = kw .pop ('flip_barb' , False )
880
895
transform = kw .pop ('transform' , ax .transData )
881
896
882
- #Flagcolor and and barbcolor provide convenience parameters for setting
883
- #the facecolor and edgecolor, respectively, of the barb polygon. We
884
- #also work here to make the flag the same color as the rest of the barb
885
- #by default
897
+ # Flagcolor and and barbcolor provide convenience parameters for
898
+ # setting the facecolor and edgecolor, respectively, of the barb
899
+ # polygon. We also work here to make the flag the same color as the
900
+ # rest of the barb by default
901
+
886
902
if None in (barbcolor , flagcolor ):
887
903
kw ['edgecolors' ] = 'face'
888
904
if flagcolor :
889
905
kw ['facecolors' ] = flagcolor
890
906
elif barbcolor :
891
907
kw ['facecolors' ] = barbcolor
892
908
else :
893
- #Set to facecolor passed in or default to black
909
+ # Set to facecolor passed in or default to black
894
910
kw .setdefault ('facecolors' , 'k' )
895
911
else :
896
912
kw ['edgecolors' ] = barbcolor
897
913
kw ['facecolors' ] = flagcolor
898
914
899
- #Parse out the data arrays from the various configurations supported
915
+ # Parse out the data arrays from the various configurations supported
900
916
x , y , u , v , c = _parse_args (* args )
901
917
self .x = x
902
918
self .y = y
903
919
xy = np .hstack ((x [:, np .newaxis ], y [:, np .newaxis ]))
904
920
905
- #Make a collection
921
+ # Make a collection
906
922
barb_size = self ._length ** 2 / 4 # Empirically determined
907
923
mcollections .PolyCollection .__init__ (self , [], (barb_size ,),
908
924
offsets = xy ,
@@ -927,8 +943,8 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
927
943
a barb is empty (too low to plot any barbs/flags.
928
944
'''
929
945
930
- #If rounding, round to the nearest multiple of half, the smallest
931
- #increment
946
+ # If rounding, round to the nearest multiple of half, the smallest
947
+ # increment
932
948
if rounding :
933
949
mag = half * (mag / half + 0.5 ).astype (np .int )
934
950
@@ -989,17 +1005,17 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
989
1005
properly align with the vector direction.
990
1006
'''
991
1007
992
- #These control the spacing and size of barb elements relative to the
993
- #length of the shaft
1008
+ # These control the spacing and size of barb elements relative to the
1009
+ # length of the shaft
994
1010
spacing = length * sizes .get ('spacing' , 0.125 )
995
1011
full_height = length * sizes .get ('height' , 0.4 )
996
1012
full_width = length * sizes .get ('width' , 0.25 )
997
1013
empty_rad = length * sizes .get ('emptybarb' , 0.15 )
998
1014
999
- #Controls y point where to pivot the barb.
1015
+ # Controls y point where to pivot the barb.
1000
1016
pivot_points = dict (tip = 0.0 , middle = - length / 2. )
1001
1017
1002
- #Check for flip
1018
+ # Check for flip
1003
1019
if flip :
1004
1020
full_height = - full_height
1005
1021
@@ -1026,11 +1042,11 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1026
1042
1027
1043
barb_list = []
1028
1044
for index , angle in np .ndenumerate (angles ):
1029
- #If the vector magnitude is too weak to draw anything, plot an
1030
- #empty circle instead
1045
+ # If the vector magnitude is too weak to draw anything, plot an
1046
+ # empty circle instead
1031
1047
if empty_flag [index ]:
1032
- #We can skip the transform since the circle has no preferred
1033
- #orientation
1048
+ # We can skip the transform since the circle has no preferred
1049
+ # orientation
1034
1050
barb_list .append (empty_barb )
1035
1051
continue
1036
1052
0 commit comments