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

Skip to content

Commit 7524ced

Browse files
committed
Deprecate implicit creation of colormaps in register_cmap()
1 parent aa18f5a commit 7524ced

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ PDF and PS character tracking internals
4747
The ``used_characters`` attribute and ``track_characters`` and
4848
``merge_used_characters`` methods of `.RendererPdf`, `.PdfFile`, and
4949
`.RendererPS` are deprecated.
50+
51+
Passing raw data to ``register_cmap()``
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
Passing raw data via parameters *data* and *lut* to ``register_cmap()`` is
54+
deprecated. Instead, create the colormap explicitly using
55+
``register_cmap(cmap=LinearSementedColormap(name, data, lut))``.

lib/matplotlib/cm.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
9090
instance. The *name* is optional; if absent, the name will
9191
be the :attr:`~matplotlib.colors.Colormap.name` attribute of the *cmap*.
9292
93-
In the second case, the three arguments are passed to
93+
The second case is deprecated. Here, the three arguments are passed to
9494
the :class:`~matplotlib.colors.LinearSegmentedColormap` initializer,
95-
and the resulting colormap is registered.
95+
and the resulting colormap is registered. Instead of this implicit
96+
colormap creation, use the first case by calling
97+
``register_cmap(cmap=LinearSementedColormap(name, data, lut))``.
9698
"""
9799
cbook._check_isinstance((str, None), name=name)
98100
if name is None:
@@ -103,6 +105,13 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
103105
if isinstance(cmap, colors.Colormap):
104106
cmap_d[name] = cmap
105107
return
108+
if lut is not None or data is not None:
109+
cbook.warn_deprecated(
110+
"3.3",
111+
message="Passing raw data via parameters data and lut to "
112+
"register_cmap() is deprecated. Instead use: "
113+
"register_cmap("
114+
"cmap=LinearSementedColormap(name, data, lut))")
106115
# For the remainder, let exceptions propagate.
107116
if lut is None:
108117
lut = mpl.rcParams['image.lut']

0 commit comments

Comments
 (0)