Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e4d951

Browse filesBrowse files
authored
Merge pull request #30005 from dstansby/remove-get-cmap
Remove cm.get_cmap
2 parents dd3e322 + 0541d6d commit 6e4d951
Copy full SHA for 6e4d951

File tree

3 files changed

+11
-39
lines changed
Filter options

3 files changed

+11
-39
lines changed
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
``matplotlib.cm.get_cmap``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Colormaps are now available through the `.ColormapRegistry` accessible via
5+
`matplotlib.colormaps` or `matplotlib.pyplot.colormaps`.
6+
7+
If you have the name of a colormap as a string, you can use a direct lookup,
8+
``matplotlib.colormaps[name]`` or ``matplotlib.pyplot.colormaps[name]`` . Alternatively, ``matplotlib.colormaps.get_cmap`` will
9+
maintain the existing behavior of additionally passing through `.Colormap` instances
10+
and converting ``None`` to the default colormap. `matplotlib.pyplot.get_cmap` will stay as a
11+
shortcut to ``matplotlib.colormaps.get_cmap``.

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
-37Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -243,43 +243,6 @@ def get_cmap(self, cmap):
243243
_bivar_colormaps = ColormapRegistry(bivar_cmaps)
244244

245245

246-
# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
247-
# caused more user trouble than expected. Re-added for 3.9.1 and extended the
248-
# deprecation period for two additional minor releases.
249-
@_api.deprecated(
250-
'3.7',
251-
removal='3.11',
252-
alternative="``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()``"
253-
" or ``pyplot.get_cmap()``"
254-
)
255-
def get_cmap(name=None, lut=None):
256-
"""
257-
Get a colormap instance, defaulting to rc values if *name* is None.
258-
259-
Parameters
260-
----------
261-
name : `~matplotlib.colors.Colormap` or str or None, default: None
262-
If a `.Colormap` instance, it will be returned. Otherwise, the name of
263-
a colormap known to Matplotlib, which will be resampled by *lut*. The
264-
default, None, means :rc:`image.cmap`.
265-
lut : int or None, default: None
266-
If *name* is not already a Colormap instance and *lut* is not None, the
267-
colormap will be resampled to have *lut* entries in the lookup table.
268-
269-
Returns
270-
-------
271-
Colormap
272-
"""
273-
name = mpl._val_or_rc(name, 'image.cmap')
274-
if isinstance(name, colors.Colormap):
275-
return name
276-
_api.check_in_list(sorted(_colormaps), name=name)
277-
if lut is None:
278-
return _colormaps[name]
279-
else:
280-
return _colormaps[name].resampled(lut)
281-
282-
283246
def _ensure_cmap(cmap):
284247
"""
285248
Ensure that we have a `.Colormap` object.

‎lib/matplotlib/cm.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.pyi
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ _colormaps: ColormapRegistry = ...
1919
_multivar_colormaps: ColormapRegistry = ...
2020
_bivar_colormaps: ColormapRegistry = ...
2121

22-
def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...
23-
2422
ScalarMappable = _ScalarMappable

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.