|
12 | 12 | Dataset and plotting using Matplotlib. |
13 | 13 | """ |
14 | 14 | import matplotlib.pyplot as plt |
| 15 | +import numpy as np |
15 | 16 |
|
16 | 17 | import metpy.calc as mpcalc |
17 | 18 | from metpy.cbook import example_data |
|
26 | 27 | # Calculate the q-vectors. Passing in a fixed value of static stability, but could also |
27 | 28 | # use `mpcalc.static_stability()`. |
28 | 29 | u_qvect, v_qvect = mpcalc.q_vector(ds.uwind, ds.vwind, ds.temperature, 850 * units.hPa, |
29 | | - static_stability=0.02 * units('J / kg / Pa^2')) |
| 30 | + static_stability=2e-6 * units('J / kg / Pa^2')) |
30 | 31 |
|
31 | 32 | # start figure and set axis |
32 | 33 | fig, ax = plt.subplots(figsize=(5, 5)) |
|
41 | 42 | cmap=plt.cm.bwr, alpha=0.75) |
42 | 43 | plt.colorbar(cf, pad=0, aspect=50) |
43 | 44 |
|
| 45 | +# calculate a scale length quantity of our vectors based on their mean |
| 46 | +scale = (np.hypot(u_qvect, v_qvect).mean() * np.sqrt(u_qvect.size)).data |
| 47 | + |
44 | 48 | # plot Q-vectors as arrows, every other arrow |
45 | 49 | qvec = ax.quiver(ds.lon.values[::2], ds.lat.values[::2], |
46 | | - u_qvect[::2, ::2] * 1e13, v_qvect[::2, ::2] * 1e13, |
47 | | - color='black', scale=1000, alpha=0.5, width=0.01) |
| 50 | + u_qvect[::2, ::2], v_qvect[::2, ::2], |
| 51 | + color='black', scale=scale.m, alpha=0.5, width=0.01) |
| 52 | + |
| 53 | +# calculate representative arrow for key |
| 54 | +key = scale / 10 |
48 | 55 |
|
49 | | -qk = ax.quiverkey(qvec, 0.8, 0.9, 200, r'$200 m^2/kg/s$', labelpos='E', |
| 56 | +# add key for arrow length |
| 57 | +qk = ax.quiverkey(qvec, 0.65, 0.905, key.m, f'{key:0.2~P}', labelpos='E', |
50 | 58 | coordinates='figure') |
51 | 59 |
|
52 | 60 | ax.set(xlim=(260, 270), ylim=(30, 40)) |
53 | | -ax.set_title('Q-Vector Calculation') |
| 61 | +ax.set_title('Q-Vector Calculation', loc='left') |
54 | 62 |
|
55 | 63 | plt.show() |
0 commit comments