1515 normalization.
1616"""
1717
18+ import copy
1819import functools
1920
2021import numpy as np
@@ -70,7 +71,7 @@ def _gen_cmap_d():
7071
7172
7273cmap_d = _gen_cmap_d ()
73- locals ().update (cmap_d )
74+ locals ().update (copy . deepcopy ( cmap_d ) )
7475
7576
7677# Continue with definitions ...
@@ -95,6 +96,9 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
9596 and the resulting colormap is registered. Instead of this implicit
9697 colormap creation, create a `.LinearSegmentedColormap` and use the first
9798 case: ``register_cmap(cmap=LinearSegmentedColormap(name, data, lut))``.
99+
100+ If *name* is the same as a built-in colormap this will replace the
101+ built-in Colormap of the same name.
98102 """
99103 cbook ._check_isinstance ((str , None ), name = name )
100104 if name is None :
@@ -124,26 +128,27 @@ def get_cmap(name=None, lut=None):
124128 """
125129 Get a colormap instance, defaulting to rc values if *name* is None.
126130
127- Colormaps added with :func:`register_cmap` take precedence over
128- built-in colormaps.
131+ Colormaps added with :func:`register_cmap` with the same name as
132+ built-in colormaps will replace them .
129133
130134 Parameters
131135 ----------
132136 name : `matplotlib.colors.Colormap` or str or None, default: None
133- If a `.Colormap` instance, it will be returned. Otherwise, the name of
134- a colormap known to Matplotlib, which will be resampled by *lut*. The
135- default, None, means :rc:`image.cmap`.
137+ If a `.Colormap` instance, a copy of it will be returned.
138+ Otherwise, the name of a colormap known to Matplotlib, which will
139+ be resampled by *lut*. A copy of the requested Colormap is always
140+ returned. The default, None, means :rc:`image.cmap`.
136141 lut : int or None, default: None
137142 If *name* is not already a Colormap instance and *lut* is not None, the
138143 colormap will be resampled to have *lut* entries in the lookup table.
139144 """
140145 if name is None :
141146 name = mpl .rcParams ['image.cmap' ]
142147 if isinstance (name , colors .Colormap ):
143- return name
148+ return copy . copy ( name )
144149 cbook ._check_in_list (sorted (cmap_d ), name = name )
145150 if lut is None :
146- return cmap_d [name ]
151+ return copy . copy ( cmap_d [name ])
147152 else :
148153 return cmap_d [name ]._resample (lut )
149154
0 commit comments