Skip to content

FIX: LogNorm masks non-positive values when vmin and vmax are equal - #32601

Merged
story645 merged 1 commit into
matplotlib:mainfrom
rcomer:lognorm-zeros
Nov 15, 2026
Merged

story645 merged 1 commit into
matplotlib:mainfrom
rcomer:lognorm-zeros

Conversation

@rcomer

@rcomer rcomer commented Nov 14, 2026

Copy link
Copy Markdown
Member

PR summary

Fixes #32599 I think.

When the norm's vmin and vmax are equal, previously we simply returned a plain numpy array of zeros. Where the scale transforms the input to invalid values we should mask those points. So use the transformed array and fill the resulting masked array with zeros.

The example from the issue now gives

mre

I'm not sure we can do much about the fact you get a different colour when the colorbar is added. I think that may have been a deliberate decision about colorbar at some point.

AI Disclosure

None used.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New features and API changes have release notes
  • [n/a] Documentation complies with general and docstring guidelines

@rcomer rcomer added the PR: bugfix Pull requests that fix identified bugs label Nov 14, 2026
@timhoffm

Copy link
Copy Markdown
Member

I'm not sure we can do much about the fact you get a different colour when the colorbar is added. I think that may have been a deliberate decision about colorbar at some point.

We have been discussing fixing this, but it’s a non-trivial topic: #26307

@rcomer

rcomer commented Nov 15, 2026 •

Copy link
Copy Markdown
Member Author

Thanks @timhoffm. I thought the problem seemed vaguely familiar but couldn’t remember where I saw it. The notes tell me I attended both of the meetings where it was discussed.

Anyway, I think we can fix the mask without worrying about the colorbar mismatch for now.

@story645
story645 merged commit 658e3ff into matplotlib:main Nov 15, 2026
44 checks passed
@rcomer
rcomer deleted the lognorm-zeros branch November 15, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: color/color & colormaps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: pcolormesh with log norm on data with zeros is broken, unless colorbar is added

3 participants