Color schemes for lines and maps, color-blind safe
Project description
Tol_colors
Color schemes for lines and maps, color-blind safe
Those color schemes were designed by Paul Tol. This repository is only packaging his work so that it can be easily installed using pip. His work and details on how to use those schemes can be found on his website, in the khroma R package documentation, or in the docs directory.
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
These schemes are discrete sets of colors meant to be used for the color of lines, text, cell background, etc. Each set can be obtained as a named tuple via:
cset = tc.get_colorset('bright')
Each color can set be accessed by name (cset.blue
for instance).
The default scheme is "bright":
An equally colorblind-safe alternative is the "vibrant" scheme:
When fewer colors are enough the "high-contrast" scheme is adapted, and also works when converted to greyscale:
The "muted" scheme has more colors but lacks a clear red or medium blue:
The "medium-contrast" scheme has three color pairs that can work in greyscale, but not as well as the high-contrast scheme:
The bright, high-contrast, vibrant, muted and medium-contrast schemes work well for plot lines and map regions, but the colors are too strong to use for backgrounds to mark (black) text, typically in a table. The "pale" scheme is designed for that purpose. The colors are inherently not very distinct from each other, but they are clear in a white area. The "dark" scheme is meant for text itself on a white background.
The "light" scheme is between the bright and pale schemes. It can be used for example for backgrounds in a table where more colors are needed than available in the pale scheme and where the colored areas are small.
Lastly, the scheme "land-cover" provides an alternative to the recommended colors for land cover data with distinct colors:
Default matplotlib colors
To change the default matplotlib colors (for lines, markers, patches, etc.), you must first obtain the list of color codes without the hexadecimal marker '#'.
To obtain this list, in a python session run [s[1:] for s in tol_colors.get_colorset("bright")]
for your set of choice.
Copy the result in either a stylesheet or your matplotlibrc file like so (here the codes are for "bright"):
axes.prop_cycle : cycler('color', ['4477AA', 'EE6677', '228833', 'CCBB44', '66CCEE', 'AA3377', 'BBBBBB'])
The sets are ordered following the technical note recommendations (not in the order shown here) and are thus adapted to this use.
Colormaps
These schemes are meant to be used as colormaps. They can be obtained by name via:
cmap = tc.get_colormap('sunset')
The colormaps are linearly interpolated (smoothed), but the sunset, BuRd, PRGn, YlOrBr and rainbow schemes can be kept discrete/segmented by adding _discrete
to the scheme name (ie tc.get_colormap('sunset_discrete')
).
The circled color is meant for bad data.
There are three diverging schemes. "sunset" is related to the ColorBrewer RdYlBu scheme, but with darker central colours and made more symmetric:
"BuRd" is the reversed ColorBrewer RdBu scheme:
"PRGn" is the ColorBrewer PRGn scheme, with green shifted to make it print-friendly:
There are three sequential schemes. "YlOrBr" is the ColorBrewer YlOrBr scheme, with orange shifted to make it print-friendly. Pale yellow can be set to completely white, for example in density histograms.
"iridescent" has a linearly varying luminance that also works in colour-blind vision. The colours should be linearly interpolated, optionally extended towards white and black.
Finally, there is a smoothed "rainbow" scheme. It is often better to use a limited range of these colors. Variants are already defined to that end. If the lowest data value occurs often, start at off-white instead of purple ("rainbow_WhRd" and "rainbow_WhBr"). If the highest data value occurs often, end at red instead of brown ("rainbow_WhRd" and "rainbow_PuRd"). For color-blind people, the light purples and light blues should not be mixed much.
There is a discrete alternative named "rainbow_discrete" where the number of colors can be picked between 1 and 23 (tc.get_colormap("rainbow_discrete", n_colors=14)
). See the technical note for details.
Simulations
Here are the color schemes with approximations of red-blind and green-blind vision:
See also
Other packages already implement these colorschemes and might better suit your needs:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tol_colors-1.4.0.tar.gz
.
File metadata
- Download URL: tol_colors-1.4.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6a9cdfeccaf5ac9e30f54dc964a63c1d84d156edce0a83c25a7d7e4dcfeb31aa
|
|
MD5 |
78033bd895370f9f4050fb33aab1b1cd
|
|
BLAKE2b-256 |
bf24fbe83555c8d143adf26309896314cf97cab97f101b3ab7730856de38c7f2
|
Provenance
The following attestation bundles were made for tol_colors-1.4.0.tar.gz
:
Publisher:
pypi-publish.yml
on Descanonge/tol_colors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
tol_colors-1.4.0.tar.gz
-
Subject digest:
6a9cdfeccaf5ac9e30f54dc964a63c1d84d156edce0a83c25a7d7e4dcfeb31aa
- Sigstore transparency entry: 195587370
- Sigstore integration time:
-
Permalink:
Descanonge/tol_colors@51afeab5178f774a89e861c96768055a5444f8fb
-
Branch / Tag:
refs/tags/v1.4.0
- Owner: https://github.com/Descanonge
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi-publish.yml@51afeab5178f774a89e861c96768055a5444f8fb
-
Trigger Event:
release
-
Statement type:
File details
Details for the file tol_colors-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: tol_colors-1.4.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9923fee8122836d21e303c589fc6cb1fde4fefcf02dabdeedadbde0733bf699f
|
|
MD5 |
aa69797027fdf88c4d3193f49dcfa9ff
|
|
BLAKE2b-256 |
83eadaecd886e0be3ddd53ddf57579874098d8a4b4472bbe606aa49c73ddb43a
|
Provenance
The following attestation bundles were made for tol_colors-1.4.0-py3-none-any.whl
:
Publisher:
pypi-publish.yml
on Descanonge/tol_colors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
tol_colors-1.4.0-py3-none-any.whl
-
Subject digest:
9923fee8122836d21e303c589fc6cb1fde4fefcf02dabdeedadbde0733bf699f
- Sigstore transparency entry: 195587372
- Sigstore integration time:
-
Permalink:
Descanonge/tol_colors@51afeab5178f774a89e861c96768055a5444f8fb
-
Branch / Tag:
refs/tags/v1.4.0
- Owner: https://github.com/Descanonge
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
pypi-publish.yml@51afeab5178f774a89e861c96768055a5444f8fb
-
Trigger Event:
release
-
Statement type: