Skip to content

FIX: quiver key pivot location #5620

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
Dec 5, 2015
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
6 changes: 5 additions & 1 deletion lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class QuiverKey(martist.Artist):
""" Labelled arrow for use as a quiver plot scale key."""
halign = {'N': 'center', 'S': 'center', 'E': 'left', 'W': 'right'}
valign = {'N': 'bottom', 'S': 'top', 'E': 'center', 'W': 'center'}
pivot = {'N': 'mid', 'S': 'mid', 'E': 'tip', 'W': 'tail'}
pivot = {'N': 'middle', 'S': 'middle', 'E': 'tip', 'W': 'tail'}

def __init__(self, Q, X, Y, U, label, **kw):
martist.Artist.__init__(self)
Expand Down Expand Up @@ -708,6 +708,10 @@ def _h_arrows(self, length):
X = X - X[:, 3, np.newaxis] # numpy bug? using -= does not
# work here unless we multiply
# by a float first, as with 'mid'.
elif self.pivot != 'tail':
raise ValueError(("Quiver.pivot must have value in {{'middle', "
"'tip', 'tail'}} not {}").format(self.pivot))

tooshort = length < self.minlength
if tooshort.any():
# Use a heptagonal dot:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def test_quiver_copy():
assert q0.V[0] == 2.0


@image_comparison(baseline_images=['quiver_key_pivot'],
extensions=['png'], remove_text=True)
def test_quiver_key_pivot():
fig, ax = plt.subplots()

u, v = np.mgrid[0:2*np.pi:10j, 0:2*np.pi:10j]

q = ax.quiver(np.sin(u), np.cos(v))
ax.set_xlim(-2, 11)
ax.set_ylim(-2, 11)
ax.quiverkey(q, 0.5, 1, 1, 'N', labelpos='N')
ax.quiverkey(q, 1, 0.5, 1, 'E', labelpos='E')
ax.quiverkey(q, 0.5, 0, 1, 'S', labelpos='S')
ax.quiverkey(q, 0, 0.5, 1, 'W', labelpos='W')


if __name__ == '__main__':
import nose
nose.runmodule()