Skip to content

Plotting with 2d coordinates, error in transposed coordinate #3138

Description

@hetland

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions