-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
What happened?
Logscale color normalization in contourf not working with locator=[ticker.LogLocator]
Matplotlib doc gives :
Automatic selection of levels works; setting the
log locator tells contourf to use a log scale:
cs = ax.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)
https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_log.html
Expected in xarray (using matplotlib plotting functions directly) :
But xarray ignores the kwarg.
data.plot.contourf(cmap=cmap, locator=ticker.LogLocator(), levels=30)
plots linear colorbar

If one uses the classic color normalization,
data.plot.contourf(cmap=cmap, , norm=matcol.LogNorm(vmin=1e-3,) levels=30)

Only part of the colormap is used (in my case positive data, only reds show in coolwarm cmap) because I beleive it samples linearly on the colormap and then show a log transofrmed colorbar.
i.e if I use levels=1000 I finally get some shades of blue

So user needs to set the logspaced levels manually.
What did you expect to happen?
No response
Minimal Complete Verifiable Example
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
No response