Potential compatibility issues with matplotlib.cm.get_cmap (Incompatible with Matplotlib 3.9.0)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 899
- PR merge metrics
- No merged PRs in 30d
Description
Context
We are currently analyzing historical GitHub issues to identify potential compatibility regressions in open-source projects. During this process, we noticed a usage pattern in OpenSfM that corresponds to a known unstable API in matplotlib (matplotlib.cm.get_cmap).
Findings
The deprecated cm.get_cmap API is used in the following files:
Evidence & History
This API has a history of instability. It was briefly removed in Matplotlib in 3.9.0, before being restored in patch releases ( 3.9.1) due to community feedback.
The rationale and future removal plan are explicitly documented in the Matplotlib 3.10.0 source code(https://github.com/matplotlib/matplotlib/blob/v3.10.0/lib/matplotlib/cm.py#L246-255):
# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
# caused more user trouble than expected. Re-added for 3.9.1 and extended the
# deprecation period for two additional minor releases.
@_api.deprecated(
'3.7',
removal='3.11',
alternative="``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()``"
" or ``pyplot.get_cmap()``"
)
def get_cmap(name=None, lut=None):
# ...
Potential Impact
- Suspected Crashes: Users whose environments happen to have
3.9.0installed likely face immediateAttributeErrorcrashes when running these scripts. - Future Incompatibility: As noted in the source code above, the API is scheduled for permanent removal in version 3.11.
Experimental Evidence
Our local testing confirms that matplotlib.cm.get_cmap was physically removed in Matplotlib 3.9.0, leading to an immediate crash.
Verification on Matplotlib 3.9.0:
>>> import matplotlib
>>> print(matplotlib.__version__)
3.9.0
>>> from matplotlib import cm
>>> cmap = cm.get_cmap(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
Suggestions
Option 1: Update API (Recommended)
Consider updating the code to use the alternatives suggested in the Matplotlib source code (e.g., matplotlib.colormaps[name] or pyplot.get_cmap()) to ensure long-term stability.
Option 2: Restrict Dependency Version
If a code update is not immediate, you might consider temporarily restricting the dependency versions in pyproject.toml to avoid the unstable releases:
dependencies = [
"matplotlib!=3.9.0,<3.11",
]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the matplotlib.cm.get_cmap usages in bin/import_colmap.py around line 109 and bin/plot_matches.py around line 35. Check the supported Matplotlib colormap alternatives and verify both scripts no longer rely on the deprecated API. Done means the scripts remain compatible with affected Matplotlib versions and avoid the reported AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100