Palettes and colour tools

The colour palettes plotastro ships, the Euclid colour schemes, and helpers for matched shades. See Colours for the guide, with swatches of the palettes.

Palettes

All palettes are plain dicts of hex strings, so pa.OKABE_ITO["blue"] works anywhere matplotlib takes a colour, and list(palette.values()) gives the colours in order.

plotastro.COLORS: dict[str, str]

The default colour-blind-friendly cycle of every style, by name. The first nine are a colour-blind-safe reordering of ColorBrewer Set1; the last three are light companions from Tableau’s Color Blind 10, for bands and de-emphasised data. Matplotlib’s "C0" to "C11" refer to the same colours.

{"blue": "#377eb8", "orange": "#ff7f00", "green": "#4daf4a",
 "pink": "#f781bf", "brown": "#a65628", "purple": "#984ea3",
 "grey": "#999999", "red": "#e41a1c", "yellow": "#dede00",
 "lightblue": "#a2c8ec", "lightorange": "#ffbc79", "lightgrey": "#ababab"}
plotastro.CYCLE: list[str]

The colours of COLORS, in cycle order.

plotastro.OKABE_ITO: dict[str, str]

Okabe & Ito (2008): the classic 8-colour palette designed for all common types of colour-vision deficiency.

{"black": "#000000", "orange": "#e69f00", "skyblue": "#56b4e9",
 "green": "#009e73", "yellow": "#f0e442", "blue": "#0072b2",
 "vermillion": "#d55e00", "purple": "#cc79a7"}
plotastro.PETROFF8: dict[str, str]

Petroff (2021), 8 colours: matplotlib’s petroff8 and the default cycle of the Euclid Consortium’s niceplots (its "categorical1" scheme, and the cycle of the euclid style).

{"blue": "#1845fb", "orange": "#ff5e02", "red": "#c91f16",
 "magenta": "#c849a9", "khaki": "#adad7d", "lightblue": "#86c8dd",
 "cornflower": "#578dff", "grey": "#656364"}
plotastro.PETROFF10: dict[str, str]

Petroff (2021), 10 colours: the colour-vision-optimised cycle that is matplotlib’s petroff10 and widely used in particle physics.

{"blue": "#3f90da", "yellow": "#ffa90e", "red": "#bd1f01",
 "grey": "#94a4a2", "purple": "#832db6", "brown": "#a96b59",
 "orange": "#e76300", "tan": "#b9ac70", "slate": "#717581",
 "cyan": "#92dadd"}
plotastro.TOL_VIBRANT: dict[str, str]

Paul Tol’s vibrant qualitative scheme: 7 colours, safe for colour-vision deficiencies. Niceplots’ "categorical3" is this palette with black in front.

{"orange": "#ee7733", "blue": "#0077bb", "cyan": "#33bbee",
 "magenta": "#ee3377", "red": "#cc3311", "teal": "#009988",
 "grey": "#bbbbbb"}
plotastro.PAIRED: dict[str, tuple[str, str]]

Light/dark pairs from ColorBrewer Paired, for data/model or before/after comparisons: PAIRED["blue"] is (light, dark). On its own this palette is not fully safe for colour-vision deficiencies (it has red and green), so pair it with line styles or markers.

{"blue": ("#a6cee3", "#1f78b4"), "green": ("#b2df8a", "#33a02c"),
 "red": ("#fb9a99", "#e31a1c"), "orange": ("#fdbf6f", "#ff7f00"),
 "purple": ("#cab2d6", "#6a3d9a"), "brown": ("#ffff99", "#b15928")}
plotastro.euclid_colors(scheme='categorical1', n=8)[source]

The colour schemes of the Euclid Consortium’s niceplots, by the names its initPlot(colortype=...) uses.

Parameters:
  • scheme (str) – "categorical1" — Petroff (2021) 8 colours, the Euclid default (PETROFF8); "categorical2" — Okabe & Ito (OKABE_ITO); "categorical3" — black followed by Tol’s vibrant scheme (TOL_VIBRANT); "sequential" — n colours of increasing brightness from the copper colormap; "diverging" — n colours from blue to red from coolwarm.

  • n (int, optional) – Number of colours for the sequential/diverging schemes (default 8; ignored for the categorical ones).

Returns:

list of str

Return type:

hex colours, in cycle order.

Examples

>>> pa.set_style("euclid", palette="categorical3")        # by name
>>> ax.set_prop_cycle(color=pa.euclid_colors("sequential", n=6))

Palette names for set_style

set_style(palette=...) makes any of these the colour cycle. Case, hyphens, underscores and spaces in the name are ignored.

palette=

colours

"default" (or "plotastro")

COLORS

"okabe_ito"

OKABE_ITO

"petroff8", "petroff10"

PETROFF8, PETROFF10

"tol_vibrant"

TOL_VIBRANT

"categorical1", "categorical2", "categorical3", "sequential", "diverging"

the Euclid schemes, from euclid_colors() (8 colours for the last two)

"cmr.<name>"

8 colours from a CMasher colormap, from cmasher_colors() (see CMasher colours and colormaps)

a list or dict of colours

those colours

Shades

plotastro.lighten(color, amount=0.5)[source]

Lighten a colour by moving it towards white.

Handy for e.g. filled uncertainty bands under a line of the same hue, without the colour shifts of alpha= where elements overlap.

Parameters:
  • color (colour) – Anything matplotlib understands (hex string, name, RGB tuple).

  • amount (float, optional) – 0 leaves the colour unchanged, 1 gives white (default 0.5). Hue and saturation are kept, so a very dark saturated colour becomes a strong, bright shade.

Returns:

(r, g, b)

Return type:

tuple of float in [0, 1]

Examples

>>> ax.plot(x, y, color=pa.COLORS["blue"])
>>> ax.fill_between(x, lo, hi, color=pa.lighten(pa.COLORS["blue"], 0.7))
plotastro.darken(color, amount=0.5)[source]

Darken a colour by moving it towards black.

Parameters:
  • color (colour) – Anything matplotlib understands (hex string, name, RGB tuple).

  • amount (float, optional) – 0 leaves the colour unchanged, 1 gives black (default 0.5). Hue and saturation are kept.

Returns:

(r, g, b)

Return type:

tuple of float in [0, 1]

Examples

>>> ax.plot(x, model, color=pa.darken(pa.COLORS["orange"], 0.3))

Swatch chart

plotastro.show_colors(palette=None, title='Default colour-blind-friendly cycle')[source]

Swatch chart of a palette: each colour with its cycle index (C0, C1, …), name and hex code.

Parameters:
  • palette (dict, optional) – {name: colour}, e.g. OKABE_ITO. Default: the colour cycle, COLORS.

  • title (str, optional) – Figure title.

Return type:

Figure

Examples

>>> pa.show_colors(pa.PETROFF10, title="Petroff (2021)")