Warning for Skew-T plot
if data are not 1D?
#3001
Closed
DanielAdriaansen
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Well the problem is that you can do perfectly sensible things with 2D arrays, like plot multiple traces in a single go: import matplotlib.pyplot as plt
import numpy as np
import metpy.calc as mpcalc
from metpy.plots import SkewT
from metpy.units import units, concatenate
p = np.array([1000., 925, 850, 700, 500, 400, 300, 200, 100]) * units.hPa
T = concatenate([mpcalc.dry_lapse(p, t * units.degC).reshape(-1, 1) for t in (10, 20, 30)], axis=1)
fig = plt.Figure()
skew = SkewT(fig)
skew.plot(p, T)
plt.show() So warning for just 2D inputs seems unnecessary. The next option would be to either warn for your case of an unnecessary size-1 dimension, or just call Right now |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was wondering if there would be interest in adding a warning for users that their data are not 1D inside
skewt.plot
here:MetPy/src/metpy/plots/skewt.py
Lines 369 to 370 in 27dc1c3
I spent awhile banging my head against the wall because my SkewT was showing markers only but not lines when I was passing data that had dimensions time=1, z0=40. It was an Xarray object, and even using
.values
to get a representation of the data as a NumPy object yielded an array with shape (1,40). Skew-T happily succeeded, but the results were markers only and I wanted lines, and could not figure out why for the life of me.After awhile I discovered the
(1,40)
shape issue, and per thematplotlib.pyplot.plot
docs:So, actually it was plotting the data in dimension 1 as a line (but there was no data to plot), and then dimension 2 (z0, my actual data) as markers, treating them as separate datasets.
At this point, using
squeeze()
to remove my size 1 dimension in Xarray or callingflatten()
on the NumPy object solved the problem, but it took me awhile to figure this out.Maybe it's as simple as adding some clarification to the docs that the data must be 1-dimensional, since I suppose checking the shape/length/size of all different possible
array-like
objects probably isn't worth it.The answer might also simply just be user error 🤦🏻♂️, which is also acceptable :)
Beta Was this translation helpful? Give feedback.
All reactions