Skip to main content

Create amazing perceptually uniform colormaps with ease!

Project description

perfect-cmaps

This repository 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.

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_colormap() 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perfect_cmaps-1.0.0.tar.gz (8.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perfect_cmaps-1.0.0-py3-none-any.whl (8.2 MB view details)

Uploaded Python 3

File details

Details for the file perfect_cmaps-1.0.0.tar.gz.

File metadata

  • Download URL: perfect_cmaps-1.0.0.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for perfect_cmaps-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2210038014e2d76a36e3cd54250e7cde61a953e78f5a7d1811572675fe7ff126
MD5 0909953242f6a442e36a1414412f0a15
BLAKE2b-256 d7b3769977e0020ebe7fdb63a100263642098f58825d7350df79db8ccde7619b

See more details on using hashes here.

File details

Details for the file perfect_cmaps-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: perfect_cmaps-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for perfect_cmaps-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4a181cbde19cf99611369ece6645032b71dd668314a8a51b1362f0867c76bb
MD5 1bfd2efaa64517e9b5d38767b9737125
BLAKE2b-256 3b04f5266fdf4e6db9c3162a0c080d2adad6aa0ed45e7652063879848a1f88c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page