monet.plots.colorbars
Colorbar helper functions
Functions
|
Return a discrete colormap from a continuous colormap. |
|
Create a colorbar with discrete colors and custom tick labels. |
- monet.plots.colorbars.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)
- monet.plots.colorbars.colorbar_index(ncolors, cmap, minval=None, maxval=None, dtype='int', basemap=None)
Create a colorbar with discrete colors and custom tick labels.
- Parameters:
ncolors (int) – Number of discrete colors to use in the colorbar.
cmap (str or matplotlib.colors.Colormap) – Colormap to discretize and use for the colorbar.
minval (float, optional) – Minimum value for the colorbar tick labels. If None and maxval is None, tick labels will range from 0 to ncolors. If None and maxval is provided, tick labels will range from 0 to maxval.
maxval (float, optional) – Maximum value for the colorbar tick labels. If None, tick labels will range from 0 or minval to ncolors.
dtype (str or type, default “int”) – Data type for tick label values (e.g., “int”, “float”).
basemap (matplotlib.mpl_toolkits.basemap.Basemap, optional) – Basemap instance to attach the colorbar to. If None, uses plt.colorbar.
- Returns:
(colorbar, discretized_cmap) where: - colorbar is the matplotlib.colorbar.Colorbar instance - discretized_cmap is the discretized colormap
- Return type: