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

Skip to content

Commit eb61e47

Browse files
committed
Deprecate implicit creation of colormaps in register_cmap()
1 parent cf6c569 commit eb61e47

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ Case-insensitive capstyles and joinstyles
5252
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5353
Please pass capstyles ("miter", "round", "bevel") and joinstyles ("butt",
5454
"round", "projecting") as lowercase.
55+
56+
Passing raw data to ``register_cmap()``
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
Passing raw data via parameters *data* and *lut* to `.register_cmap()` is
59+
deprecated. Instead, explicitly create a `.LinearSegmentedColormap` and pass
60+
it via the *cmap* parameter:
61+
``register_cmap(cmap=LinearSegmentedColormap(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, create a `.LinearSegmentedColormap` and use the first
97+
case: ``register_cmap(cmap=LinearSegmentedColormap(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=LinearSegmentedColormap(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)