Skip to content

Load cmap

pypalettes.load_cmap

load_cmap(name='random', cmap_type='discrete', reverse=False, keep_first_n=None, keep_last_n=None, keep=None, repeat=1, shuffle=False, remove=None)

Load a matplotlib colormap from one of the 2500+ available palettes.

You can find all valid palette names here

Parameters:

Name Type Description Default
name Union[str, list[str]]

Name of the palette

'random'
cmap_type str

Type of colormap: 'continuous' or 'discrete'

'discrete'
reverse bool

Whether to reverse the order of the colors or not

False
keep_first_n Optional[int]

Keep only the first n colors of the palette

None
keep Optional[list[bool]]

Specify which colors to keep in the palette

None
repeat int

The number of times the palette must be present in the output. Used to access larger palettes that are repeated.

1
shuffle Union[bool, int]

Used to mix the order of colors. If an integer is supplied, it will be used as the seed.

False
remove Optional[Union[int, list[int]]]

Remove colors at specified indices (0-indexed). Can be a single int or list of ints. For example, remove=2 removes the 3rd color, remove=[1, 3] removes the 2nd and 4th colors.

None

Returns:

Type Description
Union[LinearSegmentedColormap, ListedColormap]

A matplotlib colormap.

Examples

# mkdocs: render
import matplotlib.pyplot as plt
import numpy as np
from pypalettes import load_cmap

np.random.seed(0)
data = np.random.randn(20, 20)

cmap = load_cmap("Sunset", cmap_type="continuous")

plt.imshow(
   X=data,
   cmap=cmap
)
plt.colorbar()
# mkdocs: render
import matplotlib.pyplot as plt
import numpy as np
from pypalettes import load_cmap

np.random.seed(0)
data = np.random.randn(20, 20)

cmap = load_cmap("Acadia", cmap_type="continuous")

plt.imshow(
   X=data,
   cmap=cmap
)
plt.colorbar()
# mkdocs: render
import matplotlib.pyplot as plt
import numpy as np
from pypalettes import load_cmap

np.random.seed(0)
data = np.random.randn(20, 20)

cmap = load_cmap("Acanthurus_olivaceus", cmap_type="continuous")

plt.imshow(
   X=data,
   cmap=cmap
)
plt.colorbar()

See all palettes