Skip to main content

perfect-cmaps

This package provides Python functionality for creating custom colormaps which are perfectly perceptually uniform. The project came up as a result of there being too few easily accessible perceptually uniform colormaps, so I wanted to have a go at creating a good library where users can easily create their own. I wasn't quite happy with colormaps such as viridis, plasma or magma from matplotlib, so I started making some algorithmic colormaps.

To stay as true as possible to the lightness achieved by a true grayscale colormap, but add more information with colors, the perceptual range of colormaps is optimized to be as high as possible.

Main package functionality

  • create_cmap(): Create your own colormap.
  • get_cmap(): Get a named colormap from the library -- an instance of matplotlib.colors.LinearSegmentedColormap.
  • list_cmaps(): Lists all available local and internal colormaps.

Example of creating a custom colormap

run: python ./perfect_cmaps/customize_cmap.py --num_points 21 --lightness linear or a similar command

This specifies that your colormap will have 21 control points, which will later be interpolated for desired granularity, and that the colormap will have a linear lightness profile.

https://github.com/user-attachments/assets/a63d0c31-d799-49d0-a2cd-30c0b423378f

Generated colormap

To test out your colormap, you can use the function get_cmap() or use the main function from colormaps.py:

python ./perfect_cmaps/colormaps.py --colormap test_colormap -n 1000 --interpolation quadratic --smoothing 0.03

Here' the colormap was named test_colormap, and we specify the colormap to have 1000 points, with quadratic interpolation and some amount of smoothing applied.

Generated colormap

Test images

Test images

Here's a compilation of some colormaps generated with this library, compared with some standard colormaps available in matplotlib: Comparison

The top two colormaps, viridis and cividis have a lower perceptual range, and thus look less clear -- almost like there's a filter on them. The colormaps generated with perfect-cmaps are crisper and offer a maximal perceptual range. Additionally, the perceptual limitation for the standard colormaps is especially visible when for example a background in grayscale is very white, in which case the standard colormaps are in this case yellow and clearly do not cover the entire lightness spectrum.

Comparison2

The algorithmically created ectotherm colormap in fact covers 100 % of the perceptual range, while adding more information through colors. It ranges from completely black to completely white, while adding colors in between and maintaining truly linearly increasing lightness. This is one of my favorites! The other two displayed custom colormaps mimic viridis and cividis, but with a higher perceptual range. The standard ectotherm colormap is linear in luminance, whereas the ectotherm_l colormap is linear in lightness. I recommend the ectotherm_l colormap for general use.

Ectotherm gradient Ectotherm examples

You may have heard that standard RGB colormaps should be avoided. Well, common RGB colormaps are indeed not at all perceptually uniform, but if you design them right, you can still have a useful colormap with much color information, perceptual range and true perceptual uniformity.

Spectrum gradient Spectrum examples

Thanks to Nanoscience.com for letting me use the grayscale images as examples! Find them at https://www.nanoscience.com/techniques/scanning-electron-microscopy/.

These custom generated colormaps are theoretically perceptually uniform, but note that some screen settings may show colormap artifacts, making the colormaps appear less perceptually uniform. This may happen at lower computer screen lighting, for example.

Metadata

Release files for perfect-cmaps 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perfect-cmaps 1.4.0
File Size Uploaded
perfect_cmaps-1.4.0.tar.gz 8.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for perfect-cmaps 1.4.0
File Interpreter ABI Platform
perfect_cmaps-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 MB

Release files / perfect_cmaps-1.4.0.tar.gz

Download URL perfect_cmaps-1.4.0.tar.gz
Size 8.2 MB
Tags Source
SHA-256 checksum
How to use checksums
0f77ba867328adf1934d07951fb773262fea7c73aa0a24265c122e93014e127c
BLAKE2b-256 checksum
How to use checksums
13974e1254b0ae48702ebd7a0d2b8648401fb5c9f2a87d409900f84fc57ba45d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.3

Release files / perfect_cmaps-1.4.0-py3-none-any.whl

Download URL perfect_cmaps-1.4.0-py3-none-any.whl
Size 8.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
e18ab8d002bc112799920c49974c9b434b3bf0bb18d52aaa424ec025a2b30122
BLAKE2b-256 checksum
How to use checksums
69e8724d2fcf915808ae9032b3d4d35eb4f5ad3aadddf71ce4891ba6b1e26d65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page