Skip to content

palette

Colour helpers for the native (SVG) chart renderer.

Colour math only: nothing here draws an image. matplotlib is used, when it is installed, solely to sample named colormaps configured by the user (e.g. plot.correlation.cmap); the default palettes below do not need it.

Functions:

to_hex(color)

Normalise any colour accepted by the legacy renderer to #rrggbb.

Hex strings are handled natively; named colours ("red") are resolved through matplotlib when it is available so existing configs keep working.

mix(c1, c2, t)

Linear interpolation between two hex colours (t=0 -> c1, t=1 -> c2).

ramp(stops, t)

Sample a piecewise-linear colour ramp at t in [0, 1].

colormap_stops(name, half=False, n=11)

Return colour stops for a (matplotlib-named) colormap.

Args: name: colormap name from the config. half: keep only the upper half (used for coefficients in [0, 1]). n: number of stops to sample.

sequential_stops(color)

One-hue ramp from a light tint to the given colour (and a bit darker).

categorical(n, colors=())

First n categorical colours; configured colours take precedence.

text_on(fill)

Pick readable label ink for text drawn on top of a filled mark.