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