Skip to content

Descanonge/tol_colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tol_colors

Colormaps and qualitative colorsets that are colorblind-safe

PyPI GitHub release Tests Documentation

icon

Those color schemes were designed by Paul Tol. This repository is packaging his work so that it can be easily installed using pip. This package and its documentation follow the technical notes of the color schemes1, which are archived in this repository. Details and implementations for other languages can be found on Paul Tols's website.

A more user-friendly documentation is available at https://tol-colors.readthedocs.io, detailing how and when to use the various colorsets and colormaps in this package.

Install

Using pip:

pip install tol-colors

From source:

git clone https://github.com/Descanonge/tol_colors.git
cd tol_colors
pip install .

Show the available colorsets, colormaps, and the discrete rainbow colormap:

python -m tol_colors

Requirements

  • numpy
  • matplotlib

Discrete/qualitative schemes

Sets of colors that can be used for lines, markers, qualitative lines, etc. All colorsets are given as named tuples. You can then access the colors by index or by name:

>>> cset = tc.bright
>>> cset.blue
'#4477AA'

Each colorset is available as a module attribute (tc.bright) and stored in the dictionary tol_colors.colorsets. This is a special mapping that will accepts both hyphen and underscore versions (tc.colorsets["high-contrast"] and tc.colorsets["high_contrast"] will both work).

colorsets

This package also provides a function to easily set the default colors used by Matplotlib to one of the colorsets. This will change your matplotlibrc file or a given stylesheet file.

Colormaps

The following colormaps were created by linear interpolation of carefully chosen colors. Those colors can be used as is for discrete colormaps. These discrete variants are available by adding "_discrete" to the colormap name (eg tc.sunset_discrete). Note the iridescent does not have a readily available discrete version, and that one should use the dedicated function to obtain a discrete rainbow.

Colormaps are available as module attributes (tc.sunset), stored in a dictionnary tol_colors.colormaps (tc.colormaps["sunset"]), and registered in Matplotlib with the prefix "tol." (plt.imshow(..., cmap="tol.sunset")). Reversed variants are available by appending "_r" to the colormap name.

Rather than resampling the interpolated colormaps, discrete rainbow colormap is available by specifying the number of colors between 1 and 23 (tc.get_colormap("rainbow_discrete", n_colors=14)).

colorsmaps

See also

Other packages already implement these colorschemes and might better suit your needs:

1: Colour Schemes, Paul Tol, SRON/EPS/TN/09-002, issue 3.2, 18 August 2021

About

Color schemes for lines and maps, color-blind safe

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages