Skip to content

palettes

from charite_plot.palettes import PALETTES, make_cmap, make_palette, make_ramp

See the Palettes guide for visual palette strips and usage examples.


PALETTES

Type: dict[str, list[str]]

The Charité palettes and their hex colors:

Name Colors
primary #004d9b · #7e898f · #cbcfd2
secondary #002552 · #007bc3 · #ea5451
mono #000000 · #7e898f · #cbcfd2
light #007bc3 · #cbcfd2
versus #004d9b · #e31f2c
nineties #564091 · #88c69a · #009aa9
brickhouse #89014c · #d74b7f · #88c69a · #008939
sunrise #002552 · #007bc3 · #ffdf43 · #fab600
berryseason #d74b7f · #944292 · #6f186d · #002552 · #c8b8ad · #89725b
goldelse #fab600 · #ffdf43 · #d1d811 · #a1ba0c · #61c3d7 · #009aa9 · #7876b6 · #564091

BIH_PALETTES

Type: dict[str, list[str]]

The BIH palettes, in charite_plot.brands.bih (and BIH.palettes). Pass brand="bih" to use them by name, e.g. make_palette("accents", brand="bih").

Name Colors
primary #003754 · #668798 · #b2c3cc
accents #003754 · #009aa9 · #9d7220 · #ea5451 · #7876b6
mono #000000 · #666666 · #b2b2b2
light #009aa9 · #cccccc
versus #003754 · #ea5451

make_palette

make_palette(name_or_colors, n=None, reverse=False, brand=DEFAULT_BRAND)

Return a list of hex colors from a named palette or custom color list.

Parameters:

Name Type Description Default
name_or_colors str | list[str]

A palette name of brand (see Brand.palettes) or a list of hex color strings.

required
n int | None

Number of colors to return. None returns all colors in the palette. If n is larger than the palette, colors are linearly interpolated. If n is smaller, colors are subsampled evenly.

None
reverse bool

Reverse the palette before sampling.

False
brand str | Brand

Brand name or Brand whose palettes are searched.

DEFAULT_BRAND

make_ramp

make_ramp(name_or_colors, reverse=False, brand=DEFAULT_BRAND)

Return the color stops of a continuous scale.

Parameters:

Name Type Description Default
name_or_colors str | list[str]
  • a palette name of brand: a gradient through all its colors (like scale_color_charite(palette, discrete = FALSE) in the R package);
  • "sequential" or "diverging": the brand's continuous scales (Brand.roles; also used by the themes for heatmaps and diverging scales);
  • a color name of brand (see Brand.colors) or a hex color: a gradient from white to that color, like matplotlib's "Blues";
  • a list of hex colors: a gradient through them.

Palette names take precedence over "sequential"/"diverging", and those over color names.

required
reverse bool

Reverse the gradient.

False
brand str | Brand

Brand name or Brand whose palettes and colors are searched.

DEFAULT_BRAND

Examples:

Altair interpolates between the stops itself; interpolate="rgb" matches matplotlib:

alt.Color("value:Q", scale=alt.Scale(range=make_ramp("blau", brand="bih"), interpolate="rgb"))

make_cmap

make_cmap(name_or_colors, reverse=False, brand=DEFAULT_BRAND, n=256)

Return a continuous matplotlib colormap; see make_ramp for the accepted names.

Parameters:

Name Type Description Default
name_or_colors str | list[str]

Palette name, color name, hex color or list of hex colors (see make_ramp).

required
reverse bool

Reverse the colormap.

False
brand str | Brand

Brand name or Brand whose palettes and colors are searched.

DEFAULT_BRAND
n int

Number of entries in the colormap's lookup table.

256

Examples:

ax.imshow(data, cmap=make_cmap("prime_blue"))  # white → Charité blue
ax.scatter(x, y, c=z, cmap=make_cmap("berryseason"))  # through the whole palette