@@ -83,8 +83,6 @@ class ColormapRegistry(Mapping):
83
83
def __init__ (self , cmaps ):
84
84
self ._cmaps = cmaps
85
85
self ._builtin_cmaps = tuple (cmaps )
86
- # A shim to allow register_cmap() to force an override
87
- self ._allow_override_builtin = False
88
86
89
87
def __getitem__ (self , item ):
90
88
try :
@@ -146,10 +144,8 @@ def register(self, cmap, *, name=None, force=False):
146
144
# unless explicitly asked to
147
145
raise ValueError (
148
146
f'A colormap named "{ name } " is already registered.' )
149
- elif (name in self ._builtin_cmaps
150
- and not self ._allow_override_builtin ):
151
- # We don't allow overriding a builtin unless privately
152
- # coming from register_cmap()
147
+ elif name in self ._builtin_cmaps :
148
+ # We don't allow overriding a builtin.
153
149
raise ValueError ("Re-registering the builtin cmap "
154
150
f"{ name !r} is not allowed." )
155
151
@@ -236,129 +232,6 @@ def get_cmap(self, cmap):
236
232
globals ().update (_colormaps )
237
233
238
234
239
- @_api .deprecated ("3.7" , alternative = "``matplotlib.colormaps.register(name)``" )
240
- def register_cmap (name = None , cmap = None , * , override_builtin = False ):
241
- """
242
- Add a colormap to the set recognized by :func:`get_cmap`.
243
-
244
- Register a new colormap to be accessed by name ::
245
-
246
- LinearSegmentedColormap('swirly', data, lut)
247
- register_cmap(cmap=swirly_cmap)
248
-
249
- Parameters
250
- ----------
251
- name : str, optional
252
- The name that can be used in :func:`get_cmap` or :rc:`image.cmap`
253
-
254
- If absent, the name will be the :attr:`~matplotlib.colors.Colormap.name`
255
- attribute of the *cmap*.
256
-
257
- cmap : matplotlib.colors.Colormap
258
- Despite being the second argument and having a default value, this
259
- is a required argument.
260
-
261
- override_builtin : bool
262
-
263
- Allow built-in colormaps to be overridden by a user-supplied
264
- colormap.
265
-
266
- Please do not use this unless you are sure you need it.
267
- """
268
- _api .check_isinstance ((str , None ), name = name )
269
- if name is None :
270
- try :
271
- name = cmap .name
272
- except AttributeError as err :
273
- raise ValueError ("Arguments must include a name or a "
274
- "Colormap" ) from err
275
- # override_builtin is allowed here for backward compatibility
276
- # this is just a shim to enable that to work privately in
277
- # the global ColormapRegistry
278
- _colormaps ._allow_override_builtin = override_builtin
279
- _colormaps .register (cmap , name = name , force = override_builtin )
280
- _colormaps ._allow_override_builtin = False
281
-
282
-
283
- def _get_cmap (name = None , lut = None ):
284
- """
285
- Get a colormap instance, defaulting to rc values if *name* is None.
286
-
287
- Parameters
288
- ----------
289
- name : `~matplotlib.colors.Colormap` or str or None, default: None
290
- If a `.Colormap` instance, it will be returned. Otherwise, the name of
291
- a colormap known to Matplotlib, which will be resampled by *lut*. The
292
- default, None, means :rc:`image.cmap`.
293
- lut : int or None, default: None
294
- If *name* is not already a Colormap instance and *lut* is not None, the
295
- colormap will be resampled to have *lut* entries in the lookup table.
296
-
297
- Returns
298
- -------
299
- Colormap
300
- """
301
- if name is None :
302
- name = mpl .rcParams ['image.cmap' ]
303
- if isinstance (name , colors .Colormap ):
304
- return name
305
- _api .check_in_list (sorted (_colormaps ), name = name )
306
- if lut is None :
307
- return _colormaps [name ]
308
- else :
309
- return _colormaps [name ].resampled (lut )
310
-
311
- # do it in two steps like this so we can have an un-deprecated version in
312
- # pyplot.
313
- get_cmap = _api .deprecated (
314
- '3.7' ,
315
- name = 'get_cmap' ,
316
- alternative = (
317
- "``matplotlib.colormaps[name]`` " +
318
- "or ``matplotlib.colormaps.get_cmap(obj)``"
319
- )
320
- )(_get_cmap )
321
-
322
-
323
- @_api .deprecated ("3.7" ,
324
- alternative = "``matplotlib.colormaps.unregister(name)``" )
325
- def unregister_cmap (name ):
326
- """
327
- Remove a colormap recognized by :func:`get_cmap`.
328
-
329
- You may not remove built-in colormaps.
330
-
331
- If the named colormap is not registered, returns with no error, raises
332
- if you try to de-register a default colormap.
333
-
334
- .. warning::
335
-
336
- Colormap names are currently a shared namespace that may be used
337
- by multiple packages. Use `unregister_cmap` only if you know you
338
- have registered that name before. In particular, do not
339
- unregister just in case to clean the name before registering a
340
- new colormap.
341
-
342
- Parameters
343
- ----------
344
- name : str
345
- The name of the colormap to be un-registered
346
-
347
- Returns
348
- -------
349
- ColorMap or None
350
- If the colormap was registered, return it if not return `None`
351
-
352
- Raises
353
- ------
354
- ValueError
355
- If you try to de-register a default built-in colormap.
356
- """
357
- cmap = _colormaps .get (name , None )
358
- _colormaps .unregister (name )
359
- return cmap
360
-
361
-
362
235
def _auto_norm_from_scale (scale_cls ):
363
236
"""
364
237
Automatically generate a norm class from *scale_cls*.
0 commit comments