Skip to content

Commit 9a8b151

Browse files
authored
Merge pull request #3851 from dcamron/qvec-example
Fix Q Vector example stability and scaling
2 parents 513da89 + f0fe42f commit 9a8b151

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

examples/calculations/QVector.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Dataset and plotting using Matplotlib.
1313
"""
1414
import matplotlib.pyplot as plt
15+
import numpy as np
1516

1617
import metpy.calc as mpcalc
1718
from metpy.cbook import example_data
@@ -26,7 +27,7 @@
2627
# Calculate the q-vectors. Passing in a fixed value of static stability, but could also
2728
# use `mpcalc.static_stability()`.
2829
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'))
3031

3132
# start figure and set axis
3233
fig, ax = plt.subplots(figsize=(5, 5))
@@ -41,15 +42,22 @@
4142
cmap=plt.cm.bwr, alpha=0.75)
4243
plt.colorbar(cf, pad=0, aspect=50)
4344

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+
4448
# plot Q-vectors as arrows, every other arrow
4549
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
4855

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',
5058
coordinates='figure')
5159

5260
ax.set(xlim=(260, 270), ylim=(30, 40))
53-
ax.set_title('Q-Vector Calculation')
61+
ax.set_title('Q-Vector Calculation', loc='left')
5462

5563
plt.show()

0 commit comments

Comments
 (0)