Tools to manage colors for visualizations
This module provides access to color schemes for
qualitative (or categorical) data:
qualitative_colors()
sequential data:
sequential_colors()
diverging data:
diverging_colors()
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.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:
n <= 11 and set == ‘boynton’: Colors are chosen according to “Eleven colors that are almost never confused.” by R. M. Boynton, 1989.
n <= 12 and set == ‘tol’: Colors are chosen according to https://personal.sron.nl/~pault/colourschemes.pdf
n <= 22: Kenneth Kelly’s “22 colours of maximum contrast” are chosen (as reported by Paul Green-Armytage in https://eleanormaclure.files.wordpress.com/2011/03/colour-coding.pdf)
else: Recipe taken from https://stackoverflow.com/a/13781114
- Parameters:
n (
int
) – number of distinct colors to returnset (
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.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