@@ -65,12 +65,16 @@ def _gen_cmap_d():
6565 # Generate reversed cmaps.
6666 for cmap in list (cmap_d .values ()):
6767 rmap = cmap .reversed ()
68+ cmap ._global = True
69+ rmap ._global = True
6870 cmap_d [rmap .name ] = rmap
6971 return cmap_d
7072
7173
72- cmap_d = _gen_cmap_d ()
73- locals ().update (cmap_d )
74+ _cmap_d = _gen_cmap_d ()
75+ locals ().update (_cmap_d )
76+ # This is no longer considered public API
77+ cmap_d = _cmap_d
7478
7579
7680# Continue with definitions ...
@@ -104,7 +108,8 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
104108 raise ValueError ("Arguments must include a name or a "
105109 "Colormap" ) from err
106110 if isinstance (cmap , colors .Colormap ):
107- cmap_d [name ] = cmap
111+ cmap ._global = True
112+ _cmap_d [name ] = cmap
108113 return
109114 if lut is not None or data is not None :
110115 cbook .warn_deprecated (
@@ -117,7 +122,8 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
117122 if lut is None :
118123 lut = mpl .rcParams ['image.lut' ]
119124 cmap = colors .LinearSegmentedColormap (name , data , lut )
120- cmap_d [name ] = cmap
125+ cmap ._global = True
126+ _cmap_d [name ] = cmap
121127
122128
123129def get_cmap (name = None , lut = None ):
@@ -130,9 +136,12 @@ def get_cmap(name=None, lut=None):
130136 Parameters
131137 ----------
132138 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`.
139+ If a `.Colormap` instance, it will be returned.
140+ Otherwise, the name of a colormap known to Matplotlib, which will
141+ be resampled by *lut*. Currently, this returns the global colormap
142+ object, which is deprecated. In Matplotlib 3.5, you will no longer be
143+ able to modify the global colormaps in-place.
144+ The default, None, means :rc:`image.cmap`.
136145 lut : int or None, default: None
137146 If *name* is not already a Colormap instance and *lut* is not None, the
138147 colormap will be resampled to have *lut* entries in the lookup table.
@@ -141,11 +150,11 @@ def get_cmap(name=None, lut=None):
141150 name = mpl .rcParams ['image.cmap' ]
142151 if isinstance (name , colors .Colormap ):
143152 return name
144- cbook ._check_in_list (sorted (cmap_d ), name = name )
153+ cbook ._check_in_list (sorted (_cmap_d ), name = name )
145154 if lut is None :
146- return cmap_d [name ]
155+ return _cmap_d [name ]
147156 else :
148- return cmap_d [name ]._resample (lut )
157+ return _cmap_d [name ]._resample (lut )
149158
150159
151160class ScalarMappable :
0 commit comments