@@ -359,31 +359,53 @@ def quiverkey_doc(self):
359359 return self .__init__ .__doc__
360360
361361
362- # This is a helper function that parses out the various combination of
363- # arguments for doing colored vector plots. Pulling it out here
364- # allows both Quiver and Barbs to use it
365- def _parse_args (* args ):
366- X = Y = U = V = C = None
367- args = list (args )
368-
369- # The use of atleast_1d allows for handling scalar arguments while also
370- # keeping masked arrays
371- if len (args ) == 3 or len (args ) == 5 :
372- C = np .atleast_1d (args .pop (- 1 ))
373- V = np .atleast_1d (args .pop (- 1 ))
374- U = np .atleast_1d (args .pop (- 1 ))
375- cbook ._check_not_matrix (U = U , V = V , C = C )
376- if U .ndim == 1 :
377- nr , nc = 1 , U .shape [0 ]
362+ def _parse_args (* args , caller_name = 'function' ):
363+ """
364+ Helper function to parse positional parameters for colored vector plots.
365+
366+ This is currently used for Quiver and Barbs.
367+
368+ Parameters
369+ ----------
370+ *args : list
371+ list of 2-5 arguments. Depending on their number they are parsed to::
372+
373+ U, V
374+ U, V, C
375+ X, Y, U, V
376+ X, Y, U, V, C
377+
378+ caller_name : str
379+ Name of the calling method (used in error messages).
380+ """
381+ X = Y = C = None
382+
383+ len_args = len (args )
384+ if len_args == 2 :
385+ # The use of atleast_1d allows for handling scalar arguments while also
386+ # keeping masked arrays
387+ U , V = np .atleast_1d (* args )
388+ elif len_args == 3 :
389+ U , V , C = np .atleast_1d (* args )
390+ elif len_args == 4 :
391+ X , Y , U , V = np .atleast_1d (* args )
392+ elif len_args == 5 :
393+ X , Y , U , V , C = np .atleast_1d (* args )
378394 else :
379- nr , nc = U .shape
380- if len (args ) == 2 : # remaining after removing U,V,C
381- X , Y = [np .array (a ).ravel () for a in args ]
395+ raise TypeError (f'{ caller_name } takes 2-5 positional arguments but '
396+ f'{ len_args } were given' )
397+
398+ nr , nc = (1 , U .shape [0 ]) if U .ndim == 1 else U .shape
399+
400+ if X is not None :
401+ X = X .ravel ()
402+ Y = Y .ravel ()
382403 if len (X ) == nc and len (Y ) == nr :
383404 X , Y = [a .ravel () for a in np .meshgrid (X , Y )]
384405 else :
385406 indexgrid = np .meshgrid (np .arange (nc ), np .arange (nr ))
386407 X , Y = [np .ravel (a ) for a in indexgrid ]
408+
387409 return X , Y , U , V , C
388410
389411
@@ -425,7 +447,7 @@ def __init__(self, ax, *args,
425447 %s
426448 """
427449 self .ax = ax
428- X , Y , U , V , C = _parse_args (* args )
450+ X , Y , U , V , C = _parse_args (* args , caller_name = 'quiver()' )
429451 self .X = X
430452 self .Y = Y
431453 self .XY = np .column_stack ((X , Y ))
@@ -938,7 +960,7 @@ def __init__(self, ax, *args,
938960 kw ['linewidth' ] = 1
939961
940962 # Parse out the data arrays from the various configurations supported
941- x , y , u , v , c = _parse_args (* args )
963+ x , y , u , v , c = _parse_args (* args , caller_name = 'barbs()' )
942964 self .x = x
943965 self .y = y
944966 xy = np .column_stack ((x , y ))
0 commit comments