Skip to content

Fix Logscale color normalization in contourf #10561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion xarray/plot/dataarray_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,11 +1581,16 @@ def newplotfunc(
)

if "contour" in plotfunc.__name__:
from matplotlib import ticker

# extend is a keyword argument only for contour and contourf, but
# passing it to the colorbar is sufficient for imshow and
# pcolormesh
kwargs["extend"] = cmap_params["extend"]
kwargs["levels"] = cmap_params["levels"]
if not (
"locator" in kwargs and isinstance(kwargs["locator"], ticker.LogLocator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"locator" in kwargs and isinstance(kwargs["locator"], ticker.LogLocator)
isinstance(kwargs.get("locator"), ticker.LogLocator)

):
kwargs["levels"] = cmap_params["levels"]
# if colors == a single color, matplotlib draws dashed negative
# contours. we lose this feature if we pass cmap and not colors
if isinstance(colors, str):
Expand Down
Loading