Generate perceptually uniform colour ramps for data visualisation.
Project description
datahues
Generate perceptually uniform colour ramps for data visualisation.
Overview
datahues creates smooth, visually consistent colour gradients from a start colour to an end colour. Unlike simple RGB or HSL interpolation, which can produce perceptually uneven ramps with visible banding, this library leverages the Oklab colour space — a perceptually uniform space where equal mathematical changes correspond to equal perceptual colour differences.
Core Functions
generate_hex_list(start_hex, end_hex, n_stops=512)
Between start and end colours, generates a list of hex colour codes representing points along a smooth colour ramp. It is assumed the user wants a discrete number (n_stops) of points, so no warning is given when n_stops is small (unlike in generate_cmap below). However, if these hexes are being used to create a continuous colour ramp, it is recommended to use n_stops>=128.
- Parameters:
start_hex: Starting colour as hex code (e.g.,"#FF0000")end_hex: Ending colour as hex code (e.g.,"#0000FF")n_stops: Number of colour stops in the ramp (default: 512)
- Returns: List of hex colour codes representing the gradient
generate_cmap(start_hex, end_hex, n_stops=512, name="interp_ramp")
Betweem start and end colours, creates a Matplotlib LinearSegmentedColormap object, forming a smooth colour ramp.
- Parameters:
start_hex,end_hex,n_stops: As abovename: The "name" of the colour ramp for matplotlib internal purposes (default: "interp_ramp")
- Returns:
LinearSegmentedColormapobject ready to use in matplotlib visualisation - Warning:
n_stops < 128may produce visible banding; use larger values for smoother results
How It Works
The library converts colours through multiple colour spaces to achieve perceptual uniformity:
- Hex → RGB — Parse hex codes into normalised [0.0, 1.0] RGB values
- RGB → XYZ — Apply gamma correction and convert to CIE XYZ (D65 illuminant)
- XYZ → Oklab — Convert through LMS intermediate space to Oklab (perceptually uniform)
- Interpolate in Oklab — Create evenly-spaced values in perceptual space
- Oklab → RGB → Hex — Reverse conversion back to hex color codes
This approach ensures that visual transitions between colours feel smooth and natural across the entire gradient.
To Do
- #TODO git tag versioning
- #TODO publish to pypi
- #TODO publish to conda-forge
- #TODO example (with picture!) in README
- #TODO blogpost
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datahues-0.1.0.tar.gz.
File metadata
- Download URL: datahues-0.1.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35d50c8aaef8d4f0552f9769e61ebeec38b4b61fc998f56f443f29b694a34d9d
|
|
| MD5 |
fbc78d0005d913977b92b16bd6c4a5e2
|
|
| BLAKE2b-256 |
b5886a676221295966f0b0c2b75ace319f9d5687c007e9c4ab370f5d356b8c56
|
File details
Details for the file datahues-0.1.0-py3-none-any.whl.
File metadata
- Download URL: datahues-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
687243472e98e5c31c77bbf13a35f6443e505150311027038053cd06a149d56b
|
|
| MD5 |
b2e96a771609a5fa193f95cf7df2f119
|
|
| BLAKE2b-256 |
d065cfce9a371ff847acef2aa32aae7e22213768c2331be384d1e3f6e5d6f99a
|