Fix matplotlib>=3.9 compatibility: replace removed plt.cm.get_cmap - #205
Merged
Merged
Conversation
matplotlib deprecated `matplotlib.cm.get_cmap` in 3.7 and removed it in
3.9, so on newer matplotlib (reproduced on 3.11) any colormap export
raised:
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
This broke `python -m pingmapper test` during sonogram tile export
(sonObj._colorize_array_batched) and would also break the rectification
colormap path (rectObj) and the substrate summary plot.
Replace every `plt.cm.get_cmap(...)` call with the still-supported
`plt.get_cmap(...)` (matplotlib.pyplot.get_cmap), a drop-in that also
handles a None colormap name like the old API. The already-valid
`matplotlib.colormaps.get_cmap(...)` calls are left unchanged.
Verified by running `python -m pingmapper test` (small dataset) through
the full read -> rectify -> substrate pipeline to completion on
matplotlib 3.11.
Fixes CameronBodine#203.
Co-authored-by: HuggeK <48095810+HuggeK@users.noreply.github.com>
HuggeK
marked this pull request as ready for review
July 29, 2026 13:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #203.
On matplotlib 3.9+, running the test dataset (
python -m pingmapper test) crashes during sonogram tile export with:matplotlib.cm.get_cmapwas deprecated in matplotlib 3.7 and removed in 3.9. PINGMapper calls it asplt.cm.get_cmap(...)in several colormap paths, so any environment with a current matplotlib (reproduced here on 3.11) fails as soon as it reaches sonogram/rectified-tile colorizing.Fix
Replace every
plt.cm.get_cmap(...)with the still-supportedplt.get_cmap(...)(matplotlib.pyplot.get_cmap). This is a minimal drop-in: it returns the sameColormapobject, is not deprecated in current matplotlib, and — like the old API — gracefully handles aNonecolormap name. The already-validmatplotlib.colormaps.get_cmap(...)calls inclass_rectObj.pyare left untouched.pingmapper/class_sonObj.py_colorize_array_batched, the crash in #203)pingmapper/class_rectObj.pypingmapper/class_mapSubstrateObj.pypingmapper/class_sonObj_nadirgaptest.pyTesting
Ran
python -m pingmapper test(small dataset) on matplotlib 3.11 — the full read → rectify → substrate pipeline now runs to completion, including the previously-failing "Exporting sonogram tiles" stage.Why
plt.get_cmaprather thanmatplotlib.colormaps[name]Both work, but
plt.get_cmap(name)is the smallest possible change fromplt.cm.get_cmap(name)(just drop.cm), keeps the exact same call signature, and preserves the old behavior of acceptingNone(returns the default colormap) — whereasmatplotlib.colormaps[None]raisesKeyError.pltis already imported in every affected module, so no import changes are needed. It also matches the existingcolormaps.get_cmap(...)usage already present inclass_rectObj.py.🤖 Generated with Claude Code