@@ -949,7 +949,7 @@ def __init__(self, ax, *args,
949
949
self .fill_empty = fill_empty
950
950
self .barb_increments = barb_increments or dict ()
951
951
self .rounding = rounding
952
- self .flip = flip_barb
952
+ self .flip = np . atleast_1d ( flip_barb )
953
953
transform = kw .pop ('transform' , ax .transData )
954
954
self ._pivot = pivot
955
955
self ._length = length
@@ -1083,10 +1083,6 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1083
1083
# Controls y point where to pivot the barb.
1084
1084
pivot_points = dict (tip = 0.0 , middle = - length / 2. )
1085
1085
1086
- # Check for flip
1087
- if flip :
1088
- full_height = - full_height
1089
-
1090
1086
endx = 0.0
1091
1087
try :
1092
1088
endy = float (pivot )
@@ -1124,6 +1120,9 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1124
1120
poly_verts = [(endx , endy )]
1125
1121
offset = length
1126
1122
1123
+ # Handle if this barb should be flipped
1124
+ barb_height = - full_height if flip [index ] else full_height
1125
+
1127
1126
# Add vertices for each flag
1128
1127
for i in range (nflags [index ]):
1129
1128
# The spacing that works for the barbs is a little to much for
@@ -1133,7 +1132,7 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1133
1132
offset += spacing / 2.
1134
1133
poly_verts .extend (
1135
1134
[[endx , endy + offset ],
1136
- [endx + full_height , endy - full_width / 2 + offset ],
1135
+ [endx + barb_height , endy - full_width / 2 + offset ],
1137
1136
[endx , endy - full_width + offset ]])
1138
1137
1139
1138
offset -= full_width + spacing
@@ -1144,7 +1143,7 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1144
1143
for i in range (nbarbs [index ]):
1145
1144
poly_verts .extend (
1146
1145
[(endx , endy + offset ),
1147
- (endx + full_height , endy + offset + full_width / 2 ),
1146
+ (endx + barb_height , endy + offset + full_width / 2 ),
1148
1147
(endx , endy + offset )])
1149
1148
1150
1149
offset -= spacing
@@ -1159,7 +1158,7 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1159
1158
offset -= 1.5 * spacing
1160
1159
poly_verts .extend (
1161
1160
[(endx , endy + offset ),
1162
- (endx + full_height / 2 , endy + offset + full_width / 4 ),
1161
+ (endx + barb_height / 2 , endy + offset + full_width / 4 ),
1163
1162
(endx , endy + offset )])
1164
1163
1165
1164
# Rotate the barb according the angle. Making the barb first and
@@ -1174,15 +1173,25 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
1174
1173
def set_UVC (self , U , V , C = None ):
1175
1174
self .u = ma .masked_invalid (U , copy = False ).ravel ()
1176
1175
self .v = ma .masked_invalid (V , copy = False ).ravel ()
1176
+
1177
+ # Flip needs to have the same number of entries as everything else.
1178
+ # Use broadcast_to to avoid a bloated array of identical values.
1179
+ # (can't rely on actual broadcasting)
1180
+ if len (self .flip ) == 1 :
1181
+ flip = np .broadcast_to (self .flip , self .u .shape )
1182
+ else :
1183
+ flip = self .flip
1184
+
1177
1185
if C is not None :
1178
1186
c = ma .masked_invalid (C , copy = False ).ravel ()
1179
- x , y , u , v , c = cbook .delete_masked_points (
1180
- self .x .ravel (), self .y .ravel (), self .u , self .v , c )
1181
- _check_consistent_shapes (x , y , u , v , c )
1187
+ x , y , u , v , c , flip = cbook .delete_masked_points (
1188
+ self .x .ravel (), self .y .ravel (), self .u , self .v , c ,
1189
+ flip .ravel ())
1190
+ _check_consistent_shapes (x , y , u , v , c , flip )
1182
1191
else :
1183
- x , y , u , v = cbook .delete_masked_points (
1184
- self .x .ravel (), self .y .ravel (), self .u , self .v )
1185
- _check_consistent_shapes (x , y , u , v )
1192
+ x , y , u , v , flip = cbook .delete_masked_points (
1193
+ self .x .ravel (), self .y .ravel (), self .u , self .v , flip . ravel () )
1194
+ _check_consistent_shapes (x , y , u , v , flip )
1186
1195
1187
1196
magnitude = np .hypot (u , v )
1188
1197
flags , barbs , halves , empty = self ._find_tails (magnitude ,
@@ -1193,7 +1202,7 @@ def set_UVC(self, U, V, C=None):
1193
1202
1194
1203
plot_barbs = self ._make_barbs (u , v , flags , barbs , halves , empty ,
1195
1204
self ._length , self ._pivot , self .sizes ,
1196
- self .fill_empty , self . flip )
1205
+ self .fill_empty , flip )
1197
1206
self .set_verts (plot_barbs )
1198
1207
1199
1208
# Set the color array
0 commit comments