@@ -239,6 +239,44 @@ def get_cmap(self, cmap):
239
239
globals ().update (_colormaps )
240
240
241
241
242
+ # This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
243
+ # caused more user trouble than expected. Re-added for 3.9.1 and extended the
244
+ # deprecation period for two additional minor releases.
245
+ @_api .deprecated (
246
+ '3.7' ,
247
+ removal = '3.11' ,
248
+ alternative = "``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()``"
249
+ " or ``pyplot.get_cmap()``"
250
+ )
251
+ def get_cmap (name = None , lut = None ):
252
+ """
253
+ Get a colormap instance, defaulting to rc values if *name* is None.
254
+
255
+ Parameters
256
+ ----------
257
+ name : `~matplotlib.colors.Colormap` or str or None, default: None
258
+ If a `.Colormap` instance, it will be returned. Otherwise, the name of
259
+ a colormap known to Matplotlib, which will be resampled by *lut*. The
260
+ default, None, means :rc:`image.cmap`.
261
+ lut : int or None, default: None
262
+ If *name* is not already a Colormap instance and *lut* is not None, the
263
+ colormap will be resampled to have *lut* entries in the lookup table.
264
+
265
+ Returns
266
+ -------
267
+ Colormap
268
+ """
269
+ if name is None :
270
+ name = mpl .rcParams ['image.cmap' ]
271
+ if isinstance (name , colors .Colormap ):
272
+ return name
273
+ _api .check_in_list (sorted (_colormaps ), name = name )
274
+ if lut is None :
275
+ return _colormaps [name ]
276
+ else :
277
+ return _colormaps [name ].resampled (lut )
278
+
279
+
242
280
def _auto_norm_from_scale (scale_cls ):
243
281
"""
244
282
Automatically generate a norm class from *scale_cls*.
0 commit comments