@@ -890,9 +890,11 @@ class Barbs(mcollections.PolyCollection):
890890 From there :meth:`_make_barbs` is used to find the vertices of the
891891 polygon to represent the barb based on this information.
892892 """
893+
893894 # This may be an abuse of polygons here to render what is essentially maybe
894895 # 1 triangle and a series of lines. It works fine as far as I can tell
895896 # however.
897+
896898 @_docstring .interpd
897899 def __init__ (self , ax , * args ,
898900 pivot = 'tip' , length = 7 , barbcolor = None , flagcolor = None ,
@@ -952,35 +954,35 @@ def __init__(self, ax, *args,
952954
953955 def _find_tails (self , mag , rounding = True , half = 5 , full = 10 , flag = 50 ):
954956 """
955- Find how many of each of the tail pieces is necessary. Flag
956- specifies the increment for a flag, barb for a full barb, and half for
957- half a barb. Mag should be the magnitude of a vector (i.e., >= 0).
958-
959- This returns a tuple of:
957+ Find how many of each of the tail pieces is necessary.
960958
961- (*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)
959+ Parameters
960+ ----------
961+ mag : array
962+ Vector magnitudes; must be non-negative (and an actual ndarray).
963+ rounding : bool, default: True
964+ Whether to round or to truncate to the nearest half-barb.
965+ half, full, flag : float, defaults: 5, 10, 50
966+ Increments for a half-barb, a barb, and a flag.
962967
963- The bool *half_flag* indicates whether half of a barb is needed,
964- since there should only ever be one half on a given
965- barb. *empty_flag* flag is an array of flags to easily tell if
966- a barb is empty (too low to plot any barbs/flags.
968+ Returns
969+ -------
970+ n_flags, n_barbs : int array
971+ For each entry in *mag*, the number of flags and barbs.
972+ half_flag : bool array
973+ For each entry in *mag*, whether a half-barb is needed.
974+ empty_flag : bool array
975+ For each entry in *mag*, whether nothing is drawn.
967976 """
968-
969977 # If rounding, round to the nearest multiple of half, the smallest
970978 # increment
971979 if rounding :
972- mag = half * (mag / half + 0.5 ).astype (int )
973-
974- num_flags = np .floor (mag / flag ).astype (int )
975- mag = mag % flag
976-
977- num_barb = np .floor (mag / full ).astype (int )
978- mag = mag % full
979-
980+ mag = half * np .around (mag / half )
981+ n_flags , mag = divmod (mag , flag )
982+ n_barb , mag = divmod (mag , full )
980983 half_flag = mag >= half
981- empty_flag = ~ (half_flag | (num_flags > 0 ) | (num_barb > 0 ))
982-
983- return num_flags , num_barb , half_flag , empty_flag
984+ empty_flag = ~ (half_flag | (n_flags > 0 ) | (n_barb > 0 ))
985+ return n_flags .astype (int ), n_barb .astype (int ), half_flag , empty_flag
984986
985987 def _make_barbs (self , u , v , nflags , nbarbs , half_barb , empty_flag , length ,
986988 pivot , sizes , fill_empty , flip ):
@@ -1152,9 +1154,8 @@ def set_UVC(self, U, V, C=None):
11521154 _check_consistent_shapes (x , y , u , v , flip )
11531155
11541156 magnitude = np .hypot (u , v )
1155- flags , barbs , halves , empty = self ._find_tails (magnitude ,
1156- self .rounding ,
1157- ** self .barb_increments )
1157+ flags , barbs , halves , empty = self ._find_tails (
1158+ magnitude , self .rounding , ** self .barb_increments )
11581159
11591160 # Get the vertices for each of the barbs
11601161
0 commit comments