Note
This project is forked from hhuangwx/cmaps
Make it easier to use user defined colormaps in matplotlib. Default colormaps are from NCL and MATLAB othercolor website.
Users can define an environmental variable CMAPS_FILE_DIR
pointing to the folder containing self-defined RGB colormaps. The complete colormap pictures can be found under colormaps
directory.
This project has not yet uploaded to PyPI or Anaconda. Installing from source is required.
pip install git+https://github.com/jshn9515/cmaps.git
Import the library:
import cmaps
Get a particular colormap:
cmap = cmaps.get_cmap('testcmap')
If you want to change the colormap's order or interpolate the colormap, use the following keyword arguments:
interpolated_cmap = cmaps.get_cmap('testcmap', lutsize=128)
reversed_cmap = cmaps.get_cmap('testcmap', reverse=True)
As an alternative, you can type a valid name of colormaps ends with _r
to automatically reverse it, without manually setting reverse=True
:
reversed_cmap = cmaps.get_cmap('testcmap_r')
Get all the available colormaps:
cmap_names = cmaps.get_cmap_list()
Plot a particular colormap:
cmaps.plot_cmap('testcmap')
plot_cmap
function also accepts lutsize
and reverse
keyword argument.
-
"slicing" function like lists or numpy ndarrays is supported for colormaps:
cmap = cmaps.get_cmap('testcmap') cmap[20:-20:2] cmap[-20:20:-2]
-
"add" function for the colormaps are supported:
cmap1 = cmaps.get_cmap('testcmap') cmap2 = cmaps.get_cmap('testcmap') added_cmap = cmap1 + cmap2
-
"multiply" function is also supported, for repeating itself
num
times:cmap = cmaps.get_cmap('testcmap') multiplied_cmap = cmap * 3
-
A colormap can be interpolated (different from the "resampled" function in the new version of matplotlib which only takes the nearest ones):
cmap = cmaps.get_cmap('testcmap') interpolated_cmap = cmap.interp(50)
-
plot_cmap()
,to_list()
andto_numpy()
functions are supported:cmap = cmaps.get_cmap('testcmap') cmap.plot_cmap() cmap.to_list() cmap.to_numpy()
-
A colormap can be converted to
LinearSegmentedColormap
with different numbers of colors, with part of effect similar to interpolation:cmap = cmaps.get_cmap('testcmap') segmented_cmap = cmap.to_segment(N=100)