Avoid division by zero if headlength=0 for quiver #7525

Merged
merged 3 commits into from Nov 28, 2016
View
@@ -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)
@@ -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():