From 70fdd6e9be71cda227a617e620fa417297437dbd Mon Sep 17 00:00:00 2001 From: Mike Jarvis Date: Mon, 28 Nov 2016 03:13:26 -0500 Subject: [PATCH 1/3] Avoid division by zero if headlength=0 for quiver --- lib/matplotlib/quiver.py | 2 +- lib/matplotlib/tests/test_quiver.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 5d4caab29918..b08485b0e4a8 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -702,7 +702,7 @@ def _h_arrows(self, length): X0 = x0.take(ii) Y0 = y0.take(ii) Y0[3:-1] *= -1 - shrink = length / minsh + shrink = length / minsh if minsh > 0. else 0. X0 = shrink * X0[np.newaxis, :] Y0 = shrink * Y0[np.newaxis, :] short = np.repeat(length < minsh, 8, axis=1) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 0c13a6a437bc..8ed47f51f18d 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -59,6 +59,19 @@ def test_no_warnings(): assert len(w) == 0 +@cleanup +def test_zero_headlength(): + # Based on report by Doug McNeil: + # http://matplotlib.1069221.n5.nabble.com/quiver-warnings-td28107.html + fig, ax = plt.subplots() + X,Y = np.meshgrid(np.arange(10),np.arange(10)) + U, V = np.cos(X), np.sin(Y) + with warnings.catch_warnings(record=True) as w: + ax.quiver(U, V, headlength=0, headaxislength=0) + fig.canvas.draw() + assert len(w) == 0 + + @image_comparison(baseline_images=['quiver_animated_test_image'], extensions=['png']) def test_quiver_animate(): From 3e5aa3a990b2239ca56a10275b66abf166757f68 Mon Sep 17 00:00:00 2001 From: Mike Jarvis Date: Mon, 28 Nov 2016 03:57:33 -0500 Subject: [PATCH 2/3] Switch from > to !=, since maybe valid for minsh to be negative here. --- lib/matplotlib/quiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index b08485b0e4a8..d5c00cd53f31 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -702,7 +702,7 @@ def _h_arrows(self, length): X0 = x0.take(ii) Y0 = y0.take(ii) Y0[3:-1] *= -1 - shrink = length / minsh if minsh > 0. else 0. + shrink = length / minsh if minsh != 0. else 0. X0 = shrink * X0[np.newaxis, :] Y0 = shrink * Y0[np.newaxis, :] short = np.repeat(length < minsh, 8, axis=1) From cbc37fb6f50398e3abeb38bca8eb7f72a002fea3 Mon Sep 17 00:00:00 2001 From: Mike Jarvis Date: Mon, 28 Nov 2016 09:14:15 -0500 Subject: [PATCH 3/3] Conform to pep8 --- lib/matplotlib/tests/test_quiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index 8ed47f51f18d..096607860868 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -64,7 +64,7 @@ def test_zero_headlength(): # Based on report by Doug McNeil: # http://matplotlib.1069221.n5.nabble.com/quiver-warnings-td28107.html fig, ax = plt.subplots() - X,Y = np.meshgrid(np.arange(10),np.arange(10)) + X, Y = np.meshgrid(np.arange(10), np.arange(10)) U, V = np.cos(X), np.sin(Y) with warnings.catch_warnings(record=True) as w: ax.quiver(U, V, headlength=0, headaxislength=0)