Skip to content

Logscale color normalization in contourf #10551

@Luluser

Description

@Luluser

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) :
Image

But xarray ignores the kwarg.
data.plot.contourf(cmap=cmap, locator=ticker.LogLocator(), levels=30)
plots linear colorbar

Image

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

Image

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

Image

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

Environment

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