Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove cm.get_cmap #30005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/removals/30005-DS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
``matplotlib.cm.get_cmap``
~~~~~~~~~~~~~~~~~~~~~~~~~~

Colormaps are now available through the `.ColormapRegistry` accessible via
`matplotlib.colormaps` or `matplotlib.pyplot.colormaps`.

If you have the name of a colormap as a string, you can use a direct lookup,
``matplotlib.colormaps[name]`` or ``matplotlib.pyplot.colormaps[name]`` . Alternatively, ``matplotlib.colormaps.get_cmap`` will
maintain the existing behavior of additionally passing through `.Colormap` instances
and converting ``None`` to the default colormap. `matplotlib.pyplot.get_cmap` will stay as a
shortcut to ``matplotlib.colormaps.get_cmap``.
37 changes: 0 additions & 37 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,43 +243,6 @@ def get_cmap(self, cmap):
_bivar_colormaps = ColormapRegistry(bivar_cmaps)


# 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):
"""
Get a colormap instance, defaulting to rc values if *name* is None.

Parameters
----------
name : `~matplotlib.colors.Colormap` or str or None, default: None
If a `.Colormap` instance, it will be returned. Otherwise, the name of
a colormap known to Matplotlib, which will be resampled by *lut*. The
default, None, means :rc:`image.cmap`.
lut : int or None, default: None
If *name* is not already a Colormap instance and *lut* is not None, the
colormap will be resampled to have *lut* entries in the lookup table.

Returns
-------
Colormap
"""
name = mpl._val_or_rc(name, 'image.cmap')
if isinstance(name, colors.Colormap):
return name
_api.check_in_list(sorted(_colormaps), name=name)
if lut is None:
return _colormaps[name]
else:
return _colormaps[name].resampled(lut)


def _ensure_cmap(cmap):
"""
Ensure that we have a `.Colormap` object.
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/cm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ _colormaps: ColormapRegistry = ...
_multivar_colormaps: ColormapRegistry = ...
_bivar_colormaps: ColormapRegistry = ...

def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...

ScalarMappable = _ScalarMappable
Loading