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"].

xfloat, default = 0.0

Lower limit of the colorbar in percent.

yfloat, default = 1.0

Upper limit of the colorbar in percent.

new_cmap_namestr, 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_cmapmatplotlib.colors.LinearSegementedColormap.

The new colormap.

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")