Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 703a0ff

Browse files
authored
Merge pull request #6971 from tacaswell/fix_quiver_warnings
FIX: guard against numpy warnings
2 parents 7bf436c + 77b407f commit 703a0ff

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/matplotlib/quiver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,13 @@ def _angles_lengths(self, U, V, eps=1):
606606

607607
def _make_verts(self, U, V):
608608
uv = (U + V * 1j)
609-
if self.angles == 'xy' and self.scale_units == 'xy':
609+
str_angles = isinstance(self.angles, six.string_types)
610+
if str_angles and (self.angles == 'xy' and self.scale_units == 'xy'):
610611
# Here eps is 1 so that if we get U, V by diffing
611612
# the X, Y arrays, the vectors will connect the
612613
# points, regardless of the axis scaling (including log).
613614
angles, lengths = self._angles_lengths(U, V, eps=1)
614-
elif self.angles == 'xy' or self.scale_units == 'xy':
615+
elif str_angles and (self.angles == 'xy' or self.scale_units == 'xy'):
615616
# Calculate eps based on the extents of the plot
616617
# so that we don't end up with roundoff error from
617618
# adding a small number to a large.
@@ -644,9 +645,9 @@ def _make_verts(self, U, V):
644645
self.scale = scale * widthu_per_lenu
645646
length = a * (widthu_per_lenu / (self.scale * self.width))
646647
X, Y = self._h_arrows(length)
647-
if self.angles == 'xy':
648+
if str_angles and (self.angles == 'xy'):
648649
theta = angles
649-
elif self.angles == 'uv':
650+
elif str_angles and (self.angles == 'uv'):
650651
theta = np.angle(uv)
651652
else:
652653
# Make a copy to avoid changing the input array.

lib/matplotlib/tests/test_quiver.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import print_function
2-
import os
3-
import tempfile
2+
import warnings
43
import numpy as np
54
import sys
65
from matplotlib import pyplot as plt
@@ -45,6 +44,20 @@ def test_quiver_key_memory_leak():
4544
assert sys.getrefcount(qk) == 2
4645

4746

47+
@cleanup
48+
def test_no_warnings():
49+
fig, ax = plt.subplots()
50+
51+
X, Y = np.meshgrid(np.arange(15), np.arange(10))
52+
U = V = np.ones_like(X)
53+
54+
phi = (np.random.rand(15, 10) - .5) * 150
55+
with warnings.catch_warnings(record=True) as w:
56+
ax.quiver(X, Y, U, V, angles=phi)
57+
fig.canvas.draw()
58+
assert len(w) == 0
59+
60+
4861
@image_comparison(baseline_images=['quiver_animated_test_image'],
4962
extensions=['png'])
5063
def test_quiver_animate():

0 commit comments

Comments
 (0)