Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2db477

Browse files
committed
Merge pull request #5620 from tacaswell/fix_quiverkey
FIX: quiver key pivot location
2 parents 2f65b5b + 34d601f commit f2db477

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/matplotlib/quiver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class QuiverKey(martist.Artist):
228228
""" Labelled arrow for use as a quiver plot scale key."""
229229
halign = {'N': 'center', 'S': 'center', 'E': 'left', 'W': 'right'}
230230
valign = {'N': 'bottom', 'S': 'top', 'E': 'center', 'W': 'center'}
231-
pivot = {'N': 'mid', 'S': 'mid', 'E': 'tip', 'W': 'tail'}
231+
pivot = {'N': 'middle', 'S': 'middle', 'E': 'tip', 'W': 'tail'}
232232

233233
def __init__(self, Q, X, Y, U, label, **kw):
234234
martist.Artist.__init__(self)
@@ -708,6 +708,10 @@ def _h_arrows(self, length):
708708
X = X - X[:, 3, np.newaxis] # numpy bug? using -= does not
709709
# work here unless we multiply
710710
# by a float first, as with 'mid'.
711+
elif self.pivot != 'tail':
712+
raise ValueError(("Quiver.pivot must have value in {{'middle', "
713+
"'tip', 'tail'}} not {}").format(self.pivot))
714+
711715
tooshort = length < self.minlength
712716
if tooshort.any():
713717
# Use a heptagonal dot:

lib/matplotlib/tests/test_quiver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ def test_quiver_copy():
9292
assert q0.V[0] == 2.0
9393

9494

95+
@image_comparison(baseline_images=['quiver_key_pivot'],
96+
extensions=['png'], remove_text=True)
97+
def test_quiver_key_pivot():
98+
fig, ax = plt.subplots()
99+
100+
u, v = np.mgrid[0:2*np.pi:10j, 0:2*np.pi:10j]
101+
102+
q = ax.quiver(np.sin(u), np.cos(v))
103+
ax.set_xlim(-2, 11)
104+
ax.set_ylim(-2, 11)
105+
ax.quiverkey(q, 0.5, 1, 1, 'N', labelpos='N')
106+
ax.quiverkey(q, 1, 0.5, 1, 'E', labelpos='E')
107+
ax.quiverkey(q, 0.5, 0, 1, 'S', labelpos='S')
108+
ax.quiverkey(q, 0, 0.5, 1, 'W', labelpos='W')
109+
110+
95111
if __name__ == '__main__':
96112
import nose
97113
nose.runmodule()

0 commit comments

Comments
 (0)