@@ -445,22 +445,20 @@ def _check_consistent_shapes(*arrays):
445
445
446
446
class Quiver (mcollections .PolyCollection ):
447
447
"""
448
- Specialized PolyCollection for arrows.
449
-
450
- The only API method is set_UVC(), which can be used
451
- to change the size, orientation, and color of the
452
- arrows; their locations are fixed when the class is
453
- instantiated. Possibly this method will be useful
454
- in animations.
455
-
456
- Much of the work in this class is done in the draw()
457
- method so that as much information as possible is available
458
- about the plot. In subsequent draw() calls, recalculation
459
- is limited to things that might have changed, so there
460
- should be no performance penalty from putting the calculations
461
- in the draw() method.
448
+ Specialized `.PolyCollection` for arrows.
449
+
450
+ The only API method is `set_UVC`, which can be used to change the size,
451
+ orientation, and color of the arrows. Locations are changed using the
452
+ (inherited) `.PolyCollection.set_offsets` method. This method may be
453
+ useful in animations.
462
454
"""
463
455
456
+ # Much of the work in this class is done in the draw() method so that as
457
+ # much information as possible is available about the plot. In subsequent
458
+ # draw() calls, recalculation is limited to things that might have changed,
459
+ # so there should be no performance penalty from putting the calculations
460
+ # in the draw() method.
461
+
464
462
_PIVOT_VALS = ('tail' , 'middle' , 'tip' )
465
463
466
464
@_docstring .Substitution (_quiver_doc )
@@ -476,10 +474,6 @@ def __init__(self, ax, *args,
476
474
"""
477
475
self ._axes = ax # The attr actually set by the Artist.axes property.
478
476
X , Y , U , V , C = _parse_args (* args , caller_name = 'quiver' )
479
- self .X = X
480
- self .Y = Y
481
- self .XY = np .column_stack ((X , Y ))
482
- self .N = len (X )
483
477
self .scale = scale
484
478
self .headwidth = headwidth
485
479
self .headlength = float (headlength )
@@ -499,12 +493,18 @@ def __init__(self, ax, *args,
499
493
self .transform = kwargs .pop ('transform' , ax .transData )
500
494
kwargs .setdefault ('facecolors' , color )
501
495
kwargs .setdefault ('linewidths' , (0 ,))
502
- super ().__init__ ([], offsets = self .XY , offset_transform = self .transform ,
496
+ super ().__init__ ([], offsets = np .column_stack ([X , Y ]),
497
+ offset_transform = self .transform ,
503
498
closed = False , ** kwargs )
504
499
self .polykw = kwargs
505
500
self .set_UVC (U , V , C )
506
501
self ._dpi_at_last_init = None
507
502
503
+ XY = property (lambda self : self .get_offsets ())
504
+ X = property (lambda self : self .get_offsets ()[:, 0 ])
505
+ Y = property (lambda self : self .get_offsets ()[:, 1 ])
506
+ N = property (lambda self : len (self .get_offsets ()))
507
+
508
508
def _init (self ):
509
509
"""
510
510
Initialization delayed until first draw;
@@ -675,16 +675,14 @@ def _h_arrows(self, length):
675
675
# length = np.minimum(length, 2 ** 16)
676
676
np .clip (length , 0 , 2 ** 16 , out = length )
677
677
# x, y: normal horizontal arrow
678
- x = np .array ([0 , - self .headaxislength ,
679
- - self .headlength , 0 ],
680
- np .float64 )
678
+ x = np .array ([0 , - self .headaxislength , - self .headlength , 0 ], float )
681
679
x = x + np .array ([0 , 1 , 1 , 1 ]) * length
682
- y = 0.5 * np .array ([1 , 1 , self .headwidth , 0 ], np . float64 )
680
+ y = 0.5 * np .array ([1 , 1 , self .headwidth , 0 ], float )
683
681
y = np .repeat (y [np .newaxis , :], N , axis = 0 )
684
682
# x0, y0: arrow without shaft, for short vectors
685
683
x0 = np .array ([0 , minsh - self .headaxislength ,
686
- minsh - self .headlength , minsh ], np . float64 )
687
- y0 = 0.5 * np .array ([1 , 1 , self .headwidth , 0 ], np . float64 )
684
+ minsh - self .headlength , minsh ], float )
685
+ y0 = 0.5 * np .array ([1 , 1 , self .headwidth , 0 ], float )
688
686
ii = [0 , 1 , 2 , 3 , 2 , 1 , 0 , 0 ]
689
687
X = x [:, ii ]
690
688
Y = y [:, ii ]
@@ -866,22 +864,18 @@ def _h_arrows(self, length):
866
864
867
865
class Barbs (mcollections .PolyCollection ):
868
866
"""
869
- Specialized PolyCollection for barbs.
870
-
871
- The only API method is :meth:`set_UVC`, which can be used to
872
- change the size, orientation, and color of the arrows. Locations
873
- are changed using the :meth:`set_offsets` collection method.
874
- Possibly this method will be useful in animations.
867
+ Specialized `.PolyCollection` for barbs.
875
868
876
- There is one internal function :meth:`_find_tails` which finds
877
- exactly what should be put on the barb given the vector magnitude.
878
- From there :meth:`_make_barbs` is used to find the vertices of the
879
- polygon to represent the barb based on this information .
869
+ The only API method is `set_UVC`, which can be used to change the size,
870
+ orientation, and color of the arrows. Locations are changed using the
871
+ (inherited) `.PolyCollection.set_offsets` method. This method may be
872
+ useful in animations .
880
873
"""
881
874
882
- # This may be an abuse of polygons here to render what is essentially maybe
883
- # 1 triangle and a series of lines. It works fine as far as I can tell
884
- # however.
875
+ # There is one internal function :meth:`_find_tails` which finds
876
+ # exactly what should be put on the barb given the vector magnitude.
877
+ # From there :meth:`_make_barbs` is used to find the vertices of the
878
+ # polygon to represent the barb based on this information.
885
879
886
880
@_docstring .interpd
887
881
def __init__ (self , ax , * args ,
@@ -903,7 +897,7 @@ def __init__(self, ax, *args,
903
897
self ._pivot = pivot
904
898
self ._length = length
905
899
906
- # Flagcolor and barbcolor provide convenience parameters for
900
+ # flagcolor and barbcolor provide convenience parameters for
907
901
# setting the facecolor and edgecolor, respectively, of the barb
908
902
# polygon. We also work here to make the flag the same color as the
909
903
# rest of the barb by default
@@ -928,8 +922,6 @@ def __init__(self, ax, *args,
928
922
929
923
# Parse out the data arrays from the various configurations supported
930
924
x , y , u , v , c = _parse_args (* args , caller_name = 'barbs' )
931
- self .x = x
932
- self .y = y
933
925
xy = np .column_stack ((x , y ))
934
926
935
927
# Make a collection
@@ -940,6 +932,9 @@ def __init__(self, ax, *args,
940
932
941
933
self .set_UVC (u , v , c )
942
934
935
+ x = property (lambda self : self .get_offsets ()[:, 0 ])
936
+ y = property (lambda self : self .get_offsets ()[:, 1 ])
937
+
943
938
def _find_tails (self , mag , rounding = True , half = 5 , full = 10 , flag = 50 ):
944
939
"""
945
940
Find how many of each of the tail pieces is necessary.
0 commit comments