monet.plots.cmap_discretize
- monet.plots.cmap_discretize(cmap, N)
Return a discrete colormap from a continuous colormap.
Creates a new colormap by discretizing an existing continuous colormap into N distinct colors while preserving the color transitions.
- Parameters:
cmap (str or matplotlib.colors.Colormap) – Colormap instance or registered colormap name to discretize. Example: cm.jet, ‘viridis’, etc.
N (int) – Number of discrete colors to use in the new colormap.
- Returns:
A new colormap object with N discrete colors based on the input colormap. The name will be the original colormap name with “_N” appended.
- Return type:
Examples
>>> from numpy import arange >>> from numpy.ma import resize >>> from matplotlib.pyplot import imshow >>> from matplotlib.cm import jet >>> x = resize(arange(100), (5, 100)) >>> djet = cmap_discretize(jet, 5) >>> imshow(x, cmap=djet)