Skip to content

Create cmap

pypalettes.create_cmap

create_cmap(colors, cmap_type='discrete', name='custom_cmap')

Create a matplotlib colormap from an iterable of colors.

Parameters:

Name Type Description Default
colors List

An iterable of valid matplotlib colors. More about valid colors: https://python-graph-gallery.com/python-colors/

required
name str

A name for the palette

'custom_cmap'
cmap_type str

Type of colormap: 'continuous' or 'discrete'

'discrete'

Examples

  • Create a categorical colormap
# mkdocs: render
import matplotlib.pyplot as plt
from pypalettes import create_cmap
import numpy as np

cmap = create_cmap(["#D57A6D", "#E8B762", "#9CCDDF", "#525052"])

x = np.linspace(0, 20, 1000)
y = np.sin(x)

plt.scatter(x, y, c=y, cmap=cmap)
plt.colorbar()


  • Create a continuous colormap
# mkdocs: render
import matplotlib.pyplot as plt
from pypalettes import create_cmap
import numpy as np

cmap = create_cmap(
    ["#D57A6D", "#E8B762", "#9CCDDF", "#525052"],
    cmap_type="continuous",
)

x = np.linspace(0, 20, 1000)
y = np.sin(x)

plt.scatter(x, y, c=y, cmap=cmap)
plt.colorbar()