|
1 | 1 | ''' |
2 | | -Demonstration of quiver and quiverkey functions. This is using the |
3 | | -new version coming from the code in quiver.py. |
| 2 | +Demonstration of advanced quiver and quiverkey functions. |
4 | 3 |
|
5 | 4 | Known problem: the plot autoscaling does not take into account |
6 | 5 | the arrows, so those on the boundaries are often out of the picture. |
7 | 6 | This is *not* an easy problem to solve in a perfectly general way. |
8 | 7 | The workaround is to manually expand the axes. |
9 | | -
|
10 | 8 | ''' |
11 | 9 | import matplotlib.pyplot as plt |
12 | 10 | import numpy as np |
|
16 | 14 | U = np.cos(X) |
17 | 15 | V = np.sin(Y) |
18 | 16 |
|
19 | | -# 1 |
20 | | -plt.figure() |
21 | | -Q = plt.quiver(U, V) |
22 | | -qk = plt.quiverkey(Q, 0.5, 0.98, 2, r'$2 \frac{m}{s}$', labelpos='W', |
23 | | - fontproperties={'weight': 'bold'}) |
24 | | -l, r, b, t = plt.axis() |
25 | | -dx, dy = r - l, t - b |
26 | | -plt.axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy]) |
27 | | - |
28 | | -plt.title('Minimal arguments, no kwargs') |
29 | | - |
30 | | -# 2 |
31 | 17 | plt.figure() |
32 | 18 | Q = plt.quiver(X, Y, U, V, units='width') |
33 | 19 | qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', |
|
37 | 23 | plt.axis([-1, 7, -1, 7]) |
38 | 24 | plt.title('scales with plot width, not view') |
39 | 25 |
|
40 | | -# 3 |
41 | 26 | plt.figure() |
42 | 27 | Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], |
43 | 28 | pivot='mid', color='r', units='inches') |
|
47 | 32 | plt.axis([-1, 7, -1, 7]) |
48 | 33 | plt.title("pivot='mid'; every third arrow; units='inches'") |
49 | 34 |
|
50 | | -# 4 |
51 | 35 | plt.figure() |
52 | 36 | M = np.hypot(U, V) |
53 | 37 | Q = plt.quiver(X, Y, U, V, M, |
|
62 | 46 | plt.axis([-1, 7, -1, 7]) |
63 | 47 | plt.title("scales with x view; pivot='tip'") |
64 | 48 |
|
65 | | -# 5 |
66 | 49 | plt.figure() |
67 | 50 | Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], |
68 | 51 | color='r', units='x', |
|
72 | 55 | plt.axis([-1, 7, -1, 7]) |
73 | 56 | plt.title("triangular head; scale with x view; black edges") |
74 | 57 |
|
75 | | -# 6 |
76 | 58 | plt.figure() |
77 | 59 | M = np.zeros(U.shape, dtype='bool') |
78 | 60 | XMaskStart = U.shape[0]//3 |
|
85 | 67 | U = ma.masked_array(U, mask=M) |
86 | 68 | V = ma.masked_array(V, mask=M) |
87 | 69 | Q = plt.quiver(U, V) |
88 | | -qk = plt.quiverkey(Q, 0.5, 0.98, 2, r'$2 \frac{m}{s}$', labelpos='W', |
| 70 | +qk = plt.quiverkey(Q, 0.5, 0.96, 2, r'$2 \frac{m}{s}$', labelpos='W', |
89 | 71 | fontproperties={'weight': 'bold'}) |
90 | 72 | l, r, b, t = plt.axis() |
91 | 73 | dx, dy = r - l, t - b |
|
0 commit comments