Potential compatibility issues with matplotlib.cm.get_cmap (Incompatible with Matplotlib 3.9.0)
- Dominant language
- Python
- Stars
- 36.9k
- Forks
- 5.2k
- 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 `MockingBird` that corresponds to a known unstable API in `matplotlib` (`matplotlib.cm.get_cmap`).
### Findings
The deprecated `cm.get_cmap` API is used in [`models/encoder/inference.py`](https://github.com/babysor/MockingBird/blob/main/models/encoder/inference.py):
```python
# models/encoder/inference.py
cmap = cm.get_cmap() # <--- This line triggers AttributeError on specific versions
mappable = ax.imshow(embed, cmap=cmap)
```
### 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 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):
```python
# 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
1. **Suspected Crashes**: Users whose environments happen to have `matplotlib==3.9.0` installed likely face immediate `AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'` crashes.
2. **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:**
```python
>>> import matplotlib
>>> print(matplotlib.__version__)
3.9.0
>>> from matplotlib import cm
>>> cmap = cm.get_cmap(None)
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
```
### Suggestions
**Option 1: Update API**
Consider updating the code to use one of the official alternatives suggested in the Matplotlib source code:
* `matplotlib.colormaps[name]`
* `matplotlib.colormaps.get_cmap()`
* `pyplot.get_cmap()`
**Option 2: Restrict Dependency Version**
If a code update is not immediate, you might consider temporarily restricting the dependency versions to avoid the unstable releases:
```toml
dependencies = [
"matplotlib!=3.9.0,<3.11",
]
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in models/encoder/inference.py at the cm.get_cmap() call and reproduce the AttributeError with Matplotlib 3.9.0. Review the official alternatives cited in the issue, then verify that the embedding image renders without the compatibility error on affected and supported Matplotlib versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100