atompy.cmap_from_x_to_y#
- atompy.cmap_from_x_to_y(cmap, x=0.0, y=1.0, new_cmap_name=None, register=False)[source]#
Return a colormap within (x,y) range
- Parameters:
- cmap
A matplotlib colormap, as returned by
matplotlib.colormaps["colormap_name"].- x
float, default = 0.0 Lower limit of the colorbar in percent.
- y
float, default = 1.0 Upper limit of the colorbar in percent.
- new_cmap_name
str, optional Optionally, give the colormap a name.
If
None, colormap will be called"_new_colormap".- registerbool, default
False Register the colormap.
If it is registered, one can call it simply by it’s name (i.e.,
new_cmap_name).
- Returns:
- new_cmap
matplotlib.colors.LinearSegementedColormap. The new colormap.
- new_cmap
Examples
import matplotlib.pyplot as plt import matplotlib as mpl cmap = mpl.colormaps["viridis"] cmap_from_middle = cmap_from_x_to_y( cmap, x = 0.5, new_cmap_name = "viridis_from_middle", register = True ) # pass colormap as keyword argument plt.imshow(image, cmap=cmap_from_middle) # or, since it is registered, refer to it by name plt.imshow(image, cmap="viridis_from_middle")