Scientific colormaps for making accessible, informative and 'cmashing' plots
npx @tessl/cli install tessl/pypi-cmasher@1.9.0Scientific colormaps for making accessible, informative and "cmashing" plots. CMasher provides a comprehensive collection of perceptually uniform sequential, diverging, and cyclic colormaps designed for data visualization, along with utilities for colormap manipulation and integration with matplotlib.
pip install cmasherimport cmasher as cmrFor direct access to colormaps:
import cmasher.cm as cmrcmFor utility functions:
from cmasher import (
take_cmap_colors, view_cmap, get_cmap_type,
create_cmap_overview, combine_cmaps
)import cmasher as cmr
import matplotlib.pyplot as plt
import numpy as np
# Basic plotting with CMasher colormap
data = np.random.rand(10, 10)
plt.imshow(data, cmap='cmr.rainforest')
plt.colorbar()
plt.show()
# Extract colors from a colormap
colors = cmr.take_cmap_colors('cmr.ocean', 5, return_fmt='hex')
print(colors) # ['#000000', '#1B4F72', '#0E8474', '#A4C639', '#FFFFFF']
# View a colormap
cmr.view_cmap('cmr.iceburn', show_grayscale=True)
# Get colormap type
print(cmr.get_cmap_type('cmr.iceburn')) # 'diverging'CMasher is organized around several key components:
Access to 53 scientifically designed colormaps organized by type: sequential (37), diverging (12), and cyclic (4). All colormaps are perceptually uniform and color-vision deficiency friendly.
# Sequential colormaps
cmrcm.rainforest # ListedColormap
cmrcm.ocean # ListedColormap
cmrcm.amber # ListedColormap
# Diverging colormaps
cmrcm.iceburn # ListedColormap
cmrcm.fusion # ListedColormap
cmrcm.wildfire # ListedColormap
# Cyclic colormaps
cmrcm.seasons # ListedColormap
cmrcm.infinity # ListedColormap
# Colormap dictionaries
cmrcm.cmap_d # dict[str, ListedColormap] - all colormaps
cmrcm.cmap_cd # dict[str, dict[str, ListedColormap]] - by typeExtract colors from colormaps and analyze their properties for data visualization workflows.
def take_cmap_colors(
cmap: str | Colormap,
N: int | None,
*,
cmap_range: tuple[float, float] = (0, 1),
return_fmt: str = "float"
) -> list[tuple[float, float, float]] | list[tuple[int, int, int]] | list[str]: ...
def get_cmap_type(cmap: str | Colormap) -> str: ...
def get_cmap_list(cmap_type: str = "all") -> list[str]: ...Create visualizations of colormaps for evaluation and presentation.
def view_cmap(
cmap: str | Colormap,
*,
savefig: str | None = None,
show_test: bool = False,
show_grayscale: bool = False
) -> None: ...
def create_cmap_overview(
cmaps: list[str | Colormap] | dict[str, list[Colormap]] | None = None,
*,
savefig: str | os.PathLike[str] | None = None,
use_types: bool = True,
sort: str | Callable | None = "alphabetical",
show_grayscale: bool = True,
show_info: bool = False,
plot_profile: bool | float = False,
dark_mode: bool = False,
title: str | None = "Colormap Overview",
wscale: float = 1,
hscale: float = 1
) -> None: ...Combine and modify colormaps to create custom color schemes.
def combine_cmaps(
*cmaps: Colormap | str,
nodes: list[float] | np.ndarray | None = None,
n_rgb_levels: int = 256,
combined_cmap_name: str = "combined_cmap"
) -> LinearSegmentedColormap: ...
def get_sub_cmap(
cmap: str | Colormap,
start: float,
stop: float,
*,
N: int | None = None
) -> ListedColormap: ...Register custom colormaps and import colormap data from various formats.
def register_cmap(name: str, data: list[tuple[float, float, float]] | list[tuple[int, int, int]] | list[str]) -> None: ...
def import_cmaps(
cmap_path: str | os.PathLike[str],
*,
_skip_registration: bool = False
) -> None: ...
def create_cmap_mod(
cmap: str,
*,
save_dir: str | os.PathLike[str] = ".",
_copy_name: str | None = None
) -> str: ...Export colormaps to external applications and set up matplotlib integration features.
def update_tableau_pref_file(dirname: str | os.PathLike[str] = ".") -> None: ...
def set_cmap_legend_entry(artist: Artist, label: str) -> None: ...
def get_bibtex() -> None: ...CLI tools for colormap management, visualization, and color extraction accessible via the cmr command.
cmr bibtex # Print BibTeX citation
cmr cmlist [--type TYPE] # List available colormaps
cmr cmtype CMAP # Show colormap type
cmr cmcolors CMAP N [OPTIONS] # Extract colors from colormap
cmr cmview CMAP [OPTIONS] # View colormap
cmr mkcmod CMAP [CMAPS...] # Create standalone modulesimport os
from collections.abc import Callable
from matplotlib.colors import Colormap, ListedColormap, LinearSegmentedColormap
from matplotlib.artist import Artist
from typing import Union, TypeAlias
import numpy as np
# Core type aliases
CMAP = Union[str, Colormap]
RGB = list[tuple[float, float, float]]
RED: TypeAlias = float
GREEN: TypeAlias = float
BLUE: TypeAlias = float
# Colormap collections
cmap_d: dict[str, ListedColormap] # All colormaps by name
cmap_cd: dict[str, dict[str, ListedColormap]] # Categorized colormaps
# cmap_cd contains: "sequential", "diverging", "cyclic", "qualitative", "misc"
# Package metadata
__version__: str
__author__: str