@@ -325,6 +325,33 @@ def contains(self, mouseevent):
325325 quiverkey_doc = _quiverkey_doc
326326
327327
328+ # This is a helper function that parses out the various combination of
329+ # arguments for doing colored vector plots. Pulling it out here
330+ # allows both Quiver and Barbs to use it
331+ def _parse_args (* args ):
332+ X , Y , U , V , C = [None ]* 5
333+ args = list (args )
334+
335+ # The use of atleast_1d allows for handling scalar arguments while also
336+ # keeping masked arrays
337+ if len (args ) == 3 or len (args ) == 5 :
338+ C = np .atleast_1d (args .pop (- 1 ))
339+ V = np .atleast_1d (args .pop (- 1 ))
340+ U = np .atleast_1d (args .pop (- 1 ))
341+ if U .ndim == 1 :
342+ nr , nc = 1 , U .shape [0 ]
343+ else :
344+ nr , nc = U .shape
345+ if len (args ) == 2 : # remaining after removing U,V,C
346+ X , Y = [np .array (a ).ravel () for a in args ]
347+ if len (X ) == nc and len (Y ) == nr :
348+ X , Y = [a .ravel () for a in np .meshgrid (X , Y )]
349+ else :
350+ indexgrid = np .meshgrid (np .arange (nc ), np .arange (nr ))
351+ X , Y = [np .ravel (a ) for a in indexgrid ]
352+ return X , Y , U , V , C
353+
354+
328355class Quiver (collections .PolyCollection ):
329356 """
330357 Specialized PolyCollection for arrows.
@@ -351,7 +378,7 @@ def __init__(self, ax, *args, **kw):
351378 by the following pylab interface documentation:
352379 %s"""
353380 self .ax = ax
354- X , Y , U , V , C = self . _parse_args (* args )
381+ X , Y , U , V , C = _parse_args (* args )
355382 self .X = X
356383 self .Y = Y
357384 self .XY = np .hstack ((X [:,np .newaxis ], Y [:,np .newaxis ]))
@@ -390,26 +417,6 @@ def on_dpi_change(fig):
390417 self .ax .figure .callbacks .connect ('dpi_changed' , on_dpi_change )
391418
392419
393- def _parse_args (self , * args ):
394- X , Y , U , V , C = [None ]* 5
395- args = list (args )
396- if len (args ) == 3 or len (args ) == 5 :
397- C = np .asanyarray (args .pop (- 1 ))
398- V = np .asanyarray (args .pop (- 1 ))
399- U = np .asanyarray (args .pop (- 1 ))
400- if U .ndim == 1 :
401- nr , nc = 1 , U .shape [0 ]
402- else :
403- nr , nc = U .shape
404- if len (args ) == 2 : # remaining after removing U,V,C
405- X , Y = [np .array (a ).ravel () for a in args ]
406- if len (X ) == nc and len (Y ) == nr :
407- X , Y = [a .ravel () for a in np .meshgrid (X , Y )]
408- else :
409- indexgrid = np .meshgrid (np .arange (nc ), np .arange (nr ))
410- X , Y = [np .ravel (a ) for a in indexgrid ]
411- return X , Y , U , V , C
412-
413420 def _init (self ):
414421 """initialization delayed until first draw;
415422 allow time for axes setup.
@@ -762,7 +769,7 @@ def __init__(self, ax, *args, **kw):
762769 kw ['facecolors' ] = flagcolor
763770
764771 #Parse out the data arrays from the various configurations supported
765- x , y , u , v , c = self . _parse_args (* args )
772+ x , y , u , v , c = _parse_args (* args )
766773 self .x = x
767774 self .y = y
768775 xy = np .hstack ((x [:,np .newaxis ], y [:,np .newaxis ]))
@@ -942,28 +949,6 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
942949
943950 return barb_list
944951
945- #Taken shamelessly from Quiver
946- def _parse_args (self , * args ):
947- X , Y , U , V , C = [None ]* 5
948- args = list (args )
949- if len (args ) == 3 or len (args ) == 5 :
950- C = ma .masked_invalid (args .pop (- 1 ), copy = False ).ravel ()
951- V = ma .masked_invalid (args .pop (- 1 ), copy = False )
952- U = ma .masked_invalid (args .pop (- 1 ), copy = False )
953- nn = np .shape (U )
954- nc = nn [0 ]
955- nr = 1
956- if len (nn ) > 1 :
957- nr = nn [1 ]
958- if len (args ) == 2 : # remaining after removing U,V,C
959- X , Y = [np .array (a ).ravel () for a in args ]
960- if len (X ) == nc and len (Y ) == nr :
961- X , Y = [a .ravel () for a in np .meshgrid (X , Y )]
962- else :
963- indexgrid = np .meshgrid (np .arange (nc ), np .arange (nr ))
964- X , Y = [np .ravel (a ) for a in indexgrid ]
965- return X , Y , U , V , C
966-
967952 def set_UVC (self , U , V , C = None ):
968953 self .u = ma .masked_invalid (U , copy = False ).ravel ()
969954 self .v = ma .masked_invalid (V , copy = False ).ravel ()
0 commit comments