Skip to content

FIX: guard against numpy warnings #6971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,13 @@ def _angles_lengths(self, U, V, eps=1):

def _make_verts(self, U, V):
uv = (U + V * 1j)
if self.angles == 'xy' and self.scale_units == 'xy':
str_angles = isinstance(self.angles, six.string_types)
if str_angles and (self.angles == 'xy' and self.scale_units == 'xy'):
# Here eps is 1 so that if we get U, V by diffing
# the X, Y arrays, the vectors will connect the
# points, regardless of the axis scaling (including log).
angles, lengths = self._angles_lengths(U, V, eps=1)
elif self.angles == 'xy' or self.scale_units == 'xy':
elif str_angles and (self.angles == 'xy' or self.scale_units == 'xy'):
# Calculate eps based on the extents of the plot
# so that we don't end up with roundoff error from
# adding a small number to a large.
Expand Down Expand Up @@ -644,9 +645,9 @@ def _make_verts(self, U, V):
self.scale = scale * widthu_per_lenu
length = a * (widthu_per_lenu / (self.scale * self.width))
X, Y = self._h_arrows(length)
if self.angles == 'xy':
if str_angles and (self.angles == 'xy'):
theta = angles
elif self.angles == 'uv':
elif str_angles and (self.angles == 'uv'):
theta = np.angle(uv)
else:
# Make a copy to avoid changing the input array.
Expand Down
17 changes: 15 additions & 2 deletions lib/matplotlib/tests/test_quiver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function
import os
import tempfile
import warnings
import numpy as np
import sys
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -45,6 +44,20 @@ def test_quiver_key_memory_leak():
assert sys.getrefcount(qk) == 2


@cleanup
def test_no_warnings():
fig, ax = plt.subplots()

X, Y = np.meshgrid(np.arange(15), np.arange(10))
U = V = np.ones_like(X)

phi = (np.random.rand(15, 10) - .5) * 150
with warnings.catch_warnings(record=True) as w:
ax.quiver(X, Y, U, V, angles=phi)
fig.canvas.draw()
assert len(w) == 0


@image_comparison(baseline_images=['quiver_animated_test_image'],
extensions=['png'])
def test_quiver_animate():
Expand Down