8000 Avoid division by zero if headlength=0 for quiver by rmjarvis · Pull Request #7525 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

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 3 commits into from
Nov 28, 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
2 changes: 1 addition & 1 deletion lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
0