Skip to content

fix: use Colormap.with_extremes instead of set_bad, set_under and set_over - #263

Merged
petercorke merged 2 commits into
mainfrom
fix/mpl-cmap-extremes
Nov 23, 2026
Merged

petercorke merged 2 commits into
mainfrom
fix/mpl-cmap-extremes

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Fixes bug list items 12 and 24. Matplotlib has made Colormap.set_bad, set_under and set_over pending deprecation ("Use cmap.with_extremes(bad=...) or Colormap(bad=...) instead").

  • idisp (base/imageio.py) sets the under, over and bad colors with one cmap.with_extremes(...) call, and only for the colors that were given. It no longer needs copy.copy, because with_extremes returns a copy.
  • Image.showpixels (ImageIO.py) uses cmap.with_extremes(bad=badcolor).
  • A real bug went away with it: showpixels called set_bad on the colormap it was given, so a Colormap object passed by the caller was changed. It no longer is.

Tests, which all fail on the old code: showpixels(badcolor=) and idisp(undercolor=, overcolor=, badcolor=) raise no PendingDeprecationWarning and set the colors, and showpixels leaves the caller's colormap alone. mypy reports no issues and the full suite passes (2161 passed, 33 skipped).

AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.

🤖 Generated with Claude Code

…_over

Matplotlib has made Colormap.set_bad, set_under and set_over pending
deprecation. idisp and showpixels now use with_extremes, which returns a copy.
showpixels called set_bad on the colormap it was given, so a Colormap object
passed by the caller was changed; it no longer is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 8e4c7b9 into main Nov 23, 2026
32 checks passed
@petercorke
petercorke deleted the fix/mpl-cmap-extremes branch November 23, 2026 10:20
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant