Grayscale-safe color palettes from cubehelix.
Project description
cubehelix-studio
Cubehelix color palettes that survive grayscale, colorblindness, and print. Zero runtime dependencies; matplotlib integration available behind an optional extra.
Interactive playground: obang.pub/cubehelix-studio — adjust the parameters live in your browser.
Install
pip install cubehelix-studio # core only
pip install "cubehelix-studio[viz]" # with matplotlib adapter
# or with uv:
uv add cubehelix-studio
uv add "cubehelix-studio[viz]"
Usage
from cubehelix_studio import CubehelixParams, cubehelix, sample_sequential, to_hex
# Single point on the curve
mid = cubehelix(0.5, CubehelixParams())
# 9 evenly-spaced samples (endpoints included)
palette = sample_sequential(CubehelixParams(), 9)
[to_hex(c) for c in palette]
# => ['#000000', '#1c1338', ..., '#ffffff']
Matplotlib integration
from cubehelix_studio import CubehelixParams, to_matplotlib_colormap
import matplotlib.pyplot as plt
import numpy as np
cmap = to_matplotlib_colormap(CubehelixParams(rotations=-2.0, saturation=1.2))
plt.imshow(np.random.rand(64, 64), cmap=cmap)
plt.colorbar()
plt.show()
API
CubehelixParams
Frozen dataclass with fields:
start: float = 0.5- starting hue positionrotations: float = -1.5- rotations through the color wheelsaturation: float = 1.0- chromatic amplitudegamma: float = 1.0- gamma correction
Note: matplotlib's
cubehelix_paletteand Dave Green's 2011 paper call thesaturationfieldhue. It controls chromatic amplitude — when zero, the output is a pure greyscale ramp — sosaturationis more accurate.
cubehelix(t, params) -> tuple[float, float, float]
Returns the (r, g, b) triple at fraction t in [0, 1]. Each channel is clamped to [0, 1].
sample_sequential(params, n) -> list[tuple[float, float, float]]
Returns n colors at evenly-spaced positions i / (n - 1). Requires n >= 2.
to_hex(rgb) -> str
Formats an RGB triple as #rrggbb.
to_rgb_255(rgb) -> tuple[int, int, int]
Returns the integer 0-255 form of an RGB triple.
contrast_ratio(a, b) -> float
WCAG 2.1 contrast ratio in [1.0, 21.0].
pick_text_color(bg, candidates=None) -> tuple[float, float, float]
Returns whichever candidate has the highest contrast against bg. Defaults to [white, black].
to_matplotlib_colormap(params, n=256, name="cubehelix_studio")
Returns a matplotlib.colors.LinearSegmentedColormap. Requires the [viz] extra.
Parity with @cubehelix-studio/core
This package's math is verified against the same JSON fixture that the TypeScript reference implementation generates (fixtures/parity.json at the repo root). Both implementations must agree to within 1e-12 per channel for every parameter combination in the fixture.
License
MIT
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 cubehelix_studio-0.0.1.tar.gz.
File metadata
- Download URL: cubehelix_studio-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d75133e840f8c54e6af37e87e8e02d8c0bf71a1a1aa2c51e8e5b32d81886d36
|
|
| MD5 |
229520a6e8f8c5f0454133966376821e
|
|
| BLAKE2b-256 |
091660986eb47d19bdc919894880bf69d8245491b509c33450c97e8bdb70147d
|
Provenance
The following attestation bundles were made for cubehelix_studio-0.0.1.tar.gz:
Publisher:
release.yml on obangpub/cubehelix-studio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cubehelix_studio-0.0.1.tar.gz -
Subject digest:
4d75133e840f8c54e6af37e87e8e02d8c0bf71a1a1aa2c51e8e5b32d81886d36 - Sigstore transparency entry: 1398178087
- Sigstore integration time:
-
Permalink:
obangpub/cubehelix-studio@4444cbbb8bc74c21537fda8315d6c11127f91cf7 -
Branch / Tag:
refs/tags/python-v0.0.1 - Owner: https://github.com/obangpub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4444cbbb8bc74c21537fda8315d6c11127f91cf7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cubehelix_studio-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cubehelix_studio-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1354d2cc1dafe1e5a40de2b7a14ab898929ab3face4b6a20d38b20f2e5623ca3
|
|
| MD5 |
b911ae4587c1069f805c106807959ad2
|
|
| BLAKE2b-256 |
81cec4ef56abe76c41c3156210087a73e783e728643b28572e0170418e3de586
|
Provenance
The following attestation bundles were made for cubehelix_studio-0.0.1-py3-none-any.whl:
Publisher:
release.yml on obangpub/cubehelix-studio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cubehelix_studio-0.0.1-py3-none-any.whl -
Subject digest:
1354d2cc1dafe1e5a40de2b7a14ab898929ab3face4b6a20d38b20f2e5623ca3 - Sigstore transparency entry: 1398178096
- Sigstore integration time:
-
Permalink:
obangpub/cubehelix-studio@4444cbbb8bc74c21537fda8315d6c11127f91cf7 -
Branch / Tag:
refs/tags/python-v0.0.1 - Owner: https://github.com/obangpub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4444cbbb8bc74c21537fda8315d6c11127f91cf7 -
Trigger Event:
push
-
Statement type: