Get a colormap instance, defaulting to rc values if *name* is None. Colormaps added with :func:`register_cmap` take precedence over built-in colormaps. If *name* is a :class:`matplotlib.colors.Colormap` instance, it will be returned. If *lut* is not None it must be an int
(name=None, lut=None)
| 152 | |
| 153 | |
| 154 | def get_cmap(name=None, lut=None): |
| 155 | """ |
| 156 | Get a colormap instance, defaulting to rc values if *name* is None. |
| 157 | |
| 158 | Colormaps added with :func:`register_cmap` take precedence over |
| 159 | built-in colormaps. |
| 160 | |
| 161 | If *name* is a :class:`matplotlib.colors.Colormap` instance, it will be |
| 162 | returned. |
| 163 | |
| 164 | If *lut* is not None it must be an integer giving the number of |
| 165 | entries desired in the lookup table, and *name* must be a standard |
| 166 | mpl colormap name. |
| 167 | """ |
| 168 | if name is None: |
| 169 | name = mpl.rcParams['image.cmap'] |
| 170 | |
| 171 | if isinstance(name, colors.Colormap): |
| 172 | return name |
| 173 | |
| 174 | if name in cmap_d: |
| 175 | if lut is None: |
| 176 | return cmap_d[name] |
| 177 | else: |
| 178 | return cmap_d[name]._resample(lut) |
| 179 | else: |
| 180 | raise ValueError( |
| 181 | "Colormap %s is not recognized. Possible values are: %s" |
| 182 | % (name, ', '.join(sorted(cmap_d)))) |
| 183 | |
| 184 | |
| 185 | class ScalarMappable(object): |