Skip to content

Commit da711e1

Browse files
authored
Merge pull request #8670 from neok-m4700/upstream
FIX: str_angles and scale_units logic for quiver
2 parents 3e4e775 + 47825e9 commit da711e1

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/matplotlib/quiver.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -626,19 +626,19 @@ def _angles_lengths(self, U, V, eps=1):
626626

627627
def _make_verts(self, U, V, angles):
628628
uv = (U + V * 1j)
629-
str_angles = isinstance(angles, six.string_types)
630-
if str_angles and (angles == 'xy' and self.scale_units == 'xy'):
629+
str_angles = angles if isinstance(angles, six.string_types) else ''
630+
if str_angles == 'xy' and self.scale_units == 'xy':
631631
# Here eps is 1 so that if we get U, V by diffing
632632
# the X, Y arrays, the vectors will connect the
633633
# points, regardless of the axis scaling (including log).
634634
angles, lengths = self._angles_lengths(U, V, eps=1)
635-
elif str_angles and (angles == 'xy' or self.scale_units == 'xy'):
635+
elif str_angles == 'xy' or self.scale_units == 'xy':
636636
# Calculate eps based on the extents of the plot
637637
# so that we don't end up with roundoff error from
638638
# adding a small number to a large.
639639
eps = np.abs(self.ax.dataLim.extents).max() * 0.001
640640
angles, lengths = self._angles_lengths(U, V, eps=eps)
641-
if self.scale_units == 'xy':
641+
if str_angles and self.scale_units == 'xy':
642642
a = lengths
643643
else:
644644
a = np.abs(uv)
@@ -665,9 +665,9 @@ def _make_verts(self, U, V, angles):
665665
self.scale = scale * widthu_per_lenu
666666
length = a * (widthu_per_lenu / (self.scale * self.width))
667667
X, Y = self._h_arrows(length)
668-
if str_angles and (angles == 'xy'):
668+
if str_angles == 'xy':
669669
theta = angles
670-
elif str_angles and (angles == 'uv'):
670+
elif str_angles == 'uv':
671671
theta = np.angle(uv)
672672
else:
673673
theta = ma.masked_invalid(np.deg2rad(angles)).filled(0)

lib/matplotlib/tests/test_quiver.py

+20
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ def test_bad_masked_sizes():
167167
ax.barbs(x, y, u, v)
168168

169169

170+
def test_angles_and_scale():
171+
# angles array + scale_units kwarg
172+
fig, ax = plt.subplots()
173+
X, Y = np.meshgrid(np.arange(15), np.arange(10))
174+
U = V = np.ones_like(X)
175+
phi = (np.random.rand(15, 10) - .5) * 150
176+
ax.quiver(X, Y, U, V, angles=phi, scale_units='xy')
177+
178+
179+
@image_comparison(baseline_images=['quiver_xy'],
180+
extensions=['png'], remove_text=True)
181+
def test_quiver_xy():
182+
# simple arrow pointing from SW to NE
183+
fig, ax = plt.subplots(subplot_kw=dict(aspect='equal'))
184+
ax.quiver(0, 0, 1, 1, angles='xy', scale_units='xy', scale=1)
185+
ax.set_xlim(0, 1.1)
186+
ax.set_ylim(0, 1.1)
187+
ax.grid()
188+
189+
170190
def test_quiverkey_angles():
171191
# Check that only a single arrow is plotted for a quiverkey when an array
172192
# of angles is given to the original quiver plot

0 commit comments

Comments
 (0)