Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1383295

Browse filesBrowse files
committed
Merge pull request #4833 from ericmjl/mep12_quiver_demo.py
mep12 on quiver_demo.py
2 parents 2c95107 + 4e20961 commit 1383295
Copy full SHA for 1383295

File tree

Expand file treeCollapse file tree

1 file changed

+66
-58
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+66
-58
lines changed

‎examples/pylab_examples/quiver_demo.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/quiver_demo.py
+66-58Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,84 @@
88
The workaround is to manually expand the axes.
99
1010
'''
11-
from pylab import *
11+
import matplotlib.pyplot as plt
12+
import numpy as np
1213
from numpy import ma
1314

14-
X, Y = meshgrid(arange(0, 2*pi, .2), arange(0, 2*pi, .2))
15-
U = cos(X)
16-
V = sin(Y)
15+
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
16+
U = np.cos(X)
17+
V = np.sin(Y)
1718

18-
#1
19-
figure()
20-
Q = quiver(U, V)
21-
qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
22-
fontproperties={'weight': 'bold'})
23-
l, r, b, t = axis()
19+
# 1
20+
plt.figure()
21+
Q = plt.quiver(U, V)
22+
qk = plt.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
23+
fontproperties={'weight': 'bold'})
24+
l, r, b, t = plt.axis()
2425
dx, dy = r - l, t - b
25-
axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy])
26+
plt.axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy])
2627

27-
title('Minimal arguments, no kwargs')
28+
plt.title('Minimal arguments, no kwargs')
2829

29-
#2
30-
figure()
31-
Q = quiver(X, Y, U, V, units='width')
32-
qk = quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$',
33-
labelpos='E',
34-
coordinates='figure',
35-
fontproperties={'weight': 'bold'})
36-
axis([-1, 7, -1, 7])
37-
title('scales with plot width, not view')
30+
# 2
31+
plt.figure()
32+
Q = plt.quiver(X, Y, U, V, units='width')
33+
qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$',
34+
labelpos='E',
35+
coordinates='figure',
36+
fontproperties={'weight': 'bold'})
37+
plt.axis([-1, 7, -1, 7])
38+
plt.title('scales with plot width, not view')
3839

39-
#3
40-
figure()
41-
Q = quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
42-
pivot='mid', color='r', units='inches')
43-
qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'})
44-
plot(X[::3, ::3], Y[::3, ::3], 'k.')
45-
axis([-1, 7, -1, 7])
46-
title("pivot='mid'; every third arrow; units='inches'")
40+
# 3
41+
plt.figure()
42+
Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
43+
pivot='mid', color='r', units='inches')
44+
qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$',
45+
fontproperties={'weight': 'bold'})
46+
plt.plot(X[::3, ::3], Y[::3, ::3], 'k.')
47+
plt.axis([-1, 7, -1, 7])
48+
plt.title("pivot='mid'; every third arrow; units='inches'")
4749

48-
#4
49-
figure()
50-
M = sqrt(pow(U, 2) + pow(V, 2))
51-
Q = quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1/0.15)
52-
qk = quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$',
53-
labelpos='E',
54-
fontproperties={'weight': 'bold'})
55-
plot(X, Y, 'k.')
56-
axis([-1, 7, -1, 7])
57-
title("scales with x view; pivot='tip'")
50+
# 4
51+
plt.figure()
52+
M = np.hypot(U, V)
53+
Q = plt.quiver(X, Y, U, V, M,
54+
units='x',
55+
pivot='tip',
56+
width=0.022,
57+
scale=1 / 0.15)
58+
qk = plt.quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$',
59+
labelpos='E',
60+
fontproperties={'weight': 'bold'})
61+
plt.plot(X, Y, 'k.')
62+
plt.axis([-1, 7, -1, 7])
63+
plt.title("scales with x view; pivot='tip'")
5864

59-
#5
60-
figure()
61-
Q = quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
62-
color='r', units='x',
63-
linewidths=(2,), edgecolors=('k'), headaxislength=5)
64-
qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'})
65-
axis([-1, 7, -1, 7])
66-
title("triangular head; scale with x view; black edges")
65+
# 5
66+
plt.figure()
67+
Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
68+
color='r', units='x',
69+
linewidths=(2,), edgecolors=('k'), headaxislength=5)
70+
qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$',
71+
fontproperties={'weight': 'bold'})
72+
plt.axis([-1, 7, -1, 7])
73+
plt.title("triangular head; scale with x view; black edges")
6774

68-
#6
69-
figure()
70-
M = zeros(U.shape, dtype='bool')
71-
M[U.shape[0]/3:2*U.shape[0]/3, U.shape[1]/3:2*U.shape[1]/3] = True
75+
# 6
76+
plt.figure()
77+
M = np.zeros(U.shape, dtype='bool')
78+
M[U.shape[0]/3:2*U.shape[0]/3,
79+
U.shape[1]/3:2*U.shape[1]/3] = True
7280
U = ma.masked_array(U, mask=M)
7381
V = ma.masked_array(V, mask=M)
74-
Q = quiver(U, V)
75-
qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
76-
fontproperties={'weight': 'bold'})
77-
l, r, b, t = axis()
82+
Q = plt.quiver(U, V)
83+
qk = plt.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
84+
fontproperties={'weight': 'bold'})
85+
l, r, b, t = plt.axis()
7886
dx, dy = r - l, t - b
79-
axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy])
80-
title('Minimal arguments, no kwargs - masked values')
87+
plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy])
88+
plt.title('Minimal arguments, no kwargs - masked values')
8189

8290

83-
show()
91+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.