lgca.plots.cmap_discretize¶
- lgca.plots.cmap_discretize(cmap, N)¶
Downsample the near-continuous colormap cmap to the number of colors N.
- Parameters:
cmap (str or
matplotlib.colors.Colormap) – Colormap to be discretized, e.g.matplotlib.cm.jetor'jet'.N (
int) – Number of colors of the new colormap.
- Returns:
Discretized colormap with N colors.
Examples
>>> import numpy as np >>> import matplotlib.cm as cm >>> import matplotlib.pyplot as plt >>> x = np.resize(np.arange(100), (5,20)) >>> # discretize jet colormap >>> djet = cmap_discretize(cm.jet, 5) >>> # show color limits >>> plt.imshow(x, cmap=djet)
The name of the colormap is updated to
cmap.name + '_N':>>> djet.name 'jet_5'