home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 1446096001

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/4061#issuecomment-1446096001 https://api.github.com/repos/pydata/xarray/issues/4061 1446096001 IC_kwDOAMm_X85WMayB 60435591 2023-02-27T10:43:51Z 2023-02-27T11:16:59Z CONTRIBUTOR

As suggested by https://github.com/pydata/xarray/pull/7553#discussion_r1117264787, pass levels=bounds instead of norm=norm to data.plot(). Your example code results in a plot as expected. Would this solve your issue?

``` import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors import xarray

example from https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html

for colormap normalisation

N = 100 X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] Z1 = np.exp(-X2 - Y2) Z2 = np.exp(-(X - 1)2 - (Y - 1)2) Z = (Z1 - Z2) * 2

fig, ax = plt.subplots(2, 1, figsize=(8, 8)) ax = ax.flatten()

bounds = np.linspace(-1, 1, 10) norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)

ax[0].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r')

now add data into dataset and plot it using same normalisation

data = xarray.DataArray(Z, dims=('x', 'y'), coords={'x': X[:,0], 'y': Y[0,:]}) data.plot(ax=ax[1], x='x', y='y', levels=bounds, add_colorbar=False) ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  618141254
Powered by Datasette · Queries took 0.779ms · About: xarray-datasette