Closed
Description
This is similar to issue #1503, but specifically deals with requiring the correct order of dimensions for plotting 2d coordinates. An example of the issue is:
# create an example dataset
dates = pd.date_range('2000-01-01', '2001-12-31', name='time')
times = dates - dates[0]
x = np.linspace(0, 10, 101)
h = np.linspace(3, 7, 101)
s = np.linspace(0, 1, 51)
z = s[:, np.newaxis] * h[np.newaxis, :]
data = (np.sin(x) * np.cos(z)) * np.cos(np.asarray(times.days[:, np.newaxis, np.newaxis]))
# create an xarray dataset
ds = xr.Dataset({'data': (('time', 's', 'x'), data)},
{'time':dates, 'x':x, 's':s, 'z':(('s', 'x'), z)})
ds.coords['zt'] = ds.z.transpose()
plotting with z
and zt
should give the same results, since the dimensions are clearly labeled and other than the order of the dimensions, they are exactly the same.
This works:
ds.data[0].plot(x='x', y='z')
This does not:
ds.data[0].plot(x='x', y='zt')
Broadcasting, e.g., does not give a similar error. Specifically, this is true:
np.allclose((ds.data * ds.zt).values, (ds.data * ds.z).values)