Tools to manage colors for visualizations

This module provides access to color schemes for

as explained at https://personal.sron.nl/~pault/

Color schemes are provided through three functions, all accepting the number of different values as first argument. While py:func`sequential_colors` is limited to at most 9 values and py:func`diverging_colors` to at most 11, py:func`qualitative_colors` works with any number of values - but will use different ways to create the scheme depending on the number of values.

clldutils.color.diverging_colors(n)[source]

Between 3 and 11 diverging colors

clldutils.color.qualitative_colors(n, set=typing.Optional[str])[source]

Choses n distinct colors suitable for visualizing categorical variables.

Depending on n (and set), different algorithms to compute the colors are chosen:

Parameters:
  • n (int) – number of distinct colors to return

  • set (str) – name of a particular color set to choose from. “boynton” works for n<=11 and will choose from “Eleven colors that are almost never confused”; “tol” works for n<=12 and will choose from Paul Tol’s qualitative color scheme.

Return type:

typing.List[str]

Returns:

list of n hex color codes

clldutils.color.sequential_colors(n)[source]

Between 3 and 9 sequential colors.

clldutils.color.brightness(color)[source]

Compute the brightness of a color specified as RGB triple (or Hex triplet).

Parameters:

color (typing.Union[str, list, tuple]) –

Return type:

float

clldutils.color.is_bright(color)[source]

Compute whether a color is considered bright or not.

Note

A brightness value of 125 seems to be a common cut-off above which to regard a color as “bright”.

Parameters:

color (typing.Union[str, list, tuple]) –

Return type:

bool

clldutils.color.rgb_as_hex(s)[source]

Convert a RGB triple to a HEX triplet

Parameters:

s (typing.Union[str, list, tuple]) –

Return type:

str