Skip to content

Commit b9c3b64

Browse files
authored
Merge pull request #7525 from rmjarvis/quiver-nohead
[MRG+1] Avoid division by zero if headlength=0 for quiver
2 parents e0fcf3f + cbc37fb commit b9c3b64

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/quiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def _h_arrows(self, length):
702702
X0 = x0.take(ii)
703703
Y0 = y0.take(ii)
704704
Y0[3:-1] *= -1
705-
shrink = length / minsh
705+
shrink = length / minsh if minsh != 0. else 0.
706706
X0 = shrink * X0[np.newaxis, :]
707707
Y0 = shrink * Y0[np.newaxis, :]
708708
short = np.repeat(length < minsh, 8, axis=1)

lib/matplotlib/tests/test_quiver.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ def test_no_warnings():
5959
assert len(w) == 0
6060

6161

62+
@cleanup
63+
def test_zero_headlength():
64+
# Based on report by Doug McNeil:
65+
# http://matplotlib.1069221.n5.nabble.com/quiver-warnings-td28107.html
66+
fig, ax = plt.subplots()
67+
X, Y = np.meshgrid(np.arange(10), np.arange(10))
68+
U, V = np.cos(X), np.sin(Y)
69+
with warnings.catch_warnings(record=True) as w:
70+
ax.quiver(U, V, headlength=0, headaxislength=0)
71+
fig.canvas.draw()
72+
assert len(w) == 0
73+
74+
6275
@image_comparison(baseline_images=['quiver_animated_test_image'],
6376
extensions=['png'])
6477
def test_quiver_animate():

0 commit comments

Comments
 (0)