Skip to main content

This package provides some tools to work with colour in Python in a way that matches human perception. The adopted colour space is CIELCH, the cylindrical representation of CIELAB, with coordinates L = lightness in [0,100], C = chroma >= 0, H = hue angle in [0, 360]. The package relies on NumPy for array manipulations, Matplotlib for plotting, and optionally other colour packages listed below.

convert provides functions to convert a colour triplet between HCL and sRGB spaces, using either built-in formulas or wrappers to colorspacious or colour packages.

gamut provides functions to compute and visualize the boundary Cmax(L,H) of the sRGB gamut and of the full human gamut. These boundaries can be obtained by two methods: (1) for each point in the LCH plane, convert the colour to the target space (RGB or XYZ) and check whether it falls within the gamut; (2) get the contour points of the gamut in the space where it is naturally defined (RGB or XYZ), and convert them back to LCH space. For the latter method, to resample the function Cmax(L,H) on a regular grid the script relies on scipy.interpolate. Both methods assume knowledge of the gamut in some space, this is trivial for the sRGB gamut, not for the human gamut hence the limits script below.
The pre-computed gamuts at resolutions of 1 and 10 bins per unit L,H are included as Numpy binary files (30 MB).

limits provides functions to compute and visualize the limits of the human gamut (optimal colour stimuli, a.k.a. MacAdam limits). As explained on Bruce Lindbloom's website they are obtained by considering all possible step-functions as spectral distributions. The conversion from light spectrum to XYZ colour is made with colour (the computed limits can be compared with the crude triangulation provided by this package). To triangulate the limit surface in 3D the script relies on scipy.spatial (this is required by method 1 above).
The pre-computed limits at resolutions of 1, 5, 10, 20 nm are included as Numpy binary files (4.5 MB).

slices provides functions to draw slices in the colour space: L-H planes as a function of C (or for the maximum possible C), C-H planes as a function of L, and L-C planes as a function of H.

maps provides functions to generate colour maps for Matplotlib, and/or written as png images. Three kinds of cmaps are implemented, which separate the different perceptual dimensions: equi-luminant (varying only in H, at the max C), diverging (varying only in C between two hues H1 and H2), and mono-hue (varying only in L, at the maximum C). It includes utility functions for testing a cmap on mock data, and for displaying the path taken by a cmap in the colour space.

The package comes with five notebooks, which demonstrate the use of the five scripts.
The notebook files can be copied in the current directory using function colourspace.copy_tutorials() found in script tutorials/copy_tutorials.py. Static renderings of the notebooks can also be seen on nbviewer:
1. Conversions between colour spaces
2. Mapping the sRGB gamut
3. Mapping the human gamut
4. Slicing the LCH space
5. Making custom colour maps
Additional case study: 5.1 Helix colour scheme


This package is provided "as is", with no warranty of any kind.
The code can be freely used by whoever wants to explore modern colour theory.

Download files

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

Source Distribution

colourspace_explorer-1.5.tar.gz (21.3 MB view details)

Uploaded Source

Built Distribution

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

colourspace_explorer-1.5-py3-none-any.whl (21.3 MB view details)

Uploaded Python 3

File details

Details for the file colourspace_explorer-1.5.tar.gz.

File metadata

  • Download URL: colourspace_explorer-1.5.tar.gz
  • Upload date:
  • Size: 21.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.17

File hashes

Hashes for colourspace_explorer-1.5.tar.gz
Algorithm Hash digest
SHA256 aa6fe367aaaedf795661a9349eb6d23200cfae6d83d7b634a8b23cda910ff7e1
MD5 14c24b9e0ec1a8d1c34d4efb4274604a
BLAKE2b-256 db0021beeb4e5936764afed86cea9e5a4469e8a364e187844f1d92f4ebe77ee4

See more details on using hashes here.

File details

Details for the file colourspace_explorer-1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for colourspace_explorer-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9e66038170305f1fac88a059f133be8838d3731581081df74eeb9114a44884a2
MD5 08bdb0dd992089bbca374997e644a85a
BLAKE2b-256 417cffadb41c6efe3d5946e2da3876710c77784d1042929d8215b711923fbdf6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.5 This release

2 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