Return a color map specified through *cmap*. Parameters ---------- cmap : str or `~matplotlib.colors.Colormap` or None - if a `.Colormap`, return it - if a string, look it up in ``mpl.colormaps`` - if None, return the Colormap de
(self, cmap)
| 198 | self._cmaps.pop(name, None) |
| 199 | |
| 200 | def get_cmap(self, cmap): |
| 201 | """ |
| 202 | Return a color map specified through *cmap*. |
| 203 | |
| 204 | Parameters |
| 205 | ---------- |
| 206 | cmap : str or `~matplotlib.colors.Colormap` or None |
| 207 | |
| 208 | - if a `.Colormap`, return it |
| 209 | - if a string, look it up in ``mpl.colormaps`` |
| 210 | - if None, return the Colormap defined in :rc:`image.cmap` |
| 211 | |
| 212 | Returns |
| 213 | ------- |
| 214 | Colormap |
| 215 | """ |
| 216 | # get the default color map |
| 217 | if cmap is None: |
| 218 | return self[mpl.rcParams["image.cmap"]] |
| 219 | |
| 220 | # if the user passed in a Colormap, simply return it |
| 221 | if isinstance(cmap, colors.Colormap): |
| 222 | return cmap |
| 223 | if isinstance(cmap, str): |
| 224 | _api.check_in_list(sorted(_colormaps), cmap=cmap) |
| 225 | # otherwise, it must be a string so look it up |
| 226 | return self[cmap] |
| 227 | raise TypeError( |
| 228 | 'get_cmap expects None or an instance of a str or Colormap . ' + |
| 229 | f'you passed {cmap!r} of type {type(cmap)}' |
| 230 | ) |
| 231 | |
| 232 | |
| 233 | # public access to the colormaps should be via `matplotlib.colormaps`. For now, |
no outgoing calls