Skip to main content

C3 for Python - Consistent Categorical Colors

A pure Python port of @mapequation/c3: deterministic, distinct colors for categories and nested modules, spread over hue, lightness and chroma in OKLCH. No dependencies.

It gives the same colors as the npm package, checked against shared fixtures (within rounding), and the version numbers match, so c3-colors 2.0.0 gives the colors of @mapequation/c3 2.0.0.

Install

pip install c3-colors

or uv add c3-colors, and import it as c3. Requires Python 3.11 or later.

Usage

The API mirrors the JavaScript one, with options as keyword arguments in snake_case. The tutorial notebook walks through it with matplotlib, and colors a map with geopandas and network modules with networkx and Infomap.

import c3

c3.palette(5)
# ['#2b9bea', '#cf9f71', '#3b8559', '#b46ba5', '#00b3bb']

c3.palette(10, tone="pastel", offset=90)
c3.palette([3, 1, 1, 2])  # weights: heavier colors get more hue space
c3.palette(8, seeds=["#ff0000"], method="farthest")
c3.palette(40, end="darker")  # later colors in a darker end zone
c3.palette(12, tone={"chroma": (0.1, 0.2), "warm_hue": 60, "tilt": 0.3})
c3.palette(10, tone=c3.swatches["mural"])  # infer the tone from colors

colors = c3.hierarchy([
    {"path": [1, 1], "flow": 0.3},
    {"path": [1, 2], "flow": 0.2},
    {"path": [2, 1], "flow": 0.5},
])
colors([1, 2])  # color of module 1:2
colors.modules  # all modules with path, flow, color and radius, depth first

c3.tones["vivid"]  # {'lightness': (0.55, 0.7), 'chroma': (0.15, 0.21), 'warm_hue': 285, 'tilt': 0}
c3.infer_tone(["#e41a1c", "#377eb8", "#4daf4a"])
c3.oklab("steelblue"), c3.oklch("#2b9bea")
c3.distance("#2b9bea", "#2b9beb")  # about 0.02 is just noticeable

Tone and end zone fields are snake_case too: warm_hue for warmHue, min_gap for minGap.

Hue sources

hue is "Oklch" (the OKLCH hue circle, the default), one of the d3 color schemes "Turbo", "Sinebow" or "Rainbow", or any callable from t in [0, 1] to a color. The callable can return a CSS color string like "#rrggbb" or "rgb(r, g, b)", or a sequence of floats in [0, 1] (alpha is ignored), the convention of matplotlib colormaps:

import matplotlib

c3.palette(10, hue=matplotlib.colormaps["viridis"])

matplotlib is not a dependency. The other d3 scheme names the npm package accepts raise a ValueError; pass the scheme as a callable instead.

Development

cd python
uv run pytest
uv run --group notebook python examples/execute.py   # re-execute the tutorial in place

The tests check every case in fixtures/c3.json at the repository root, which the TypeScript library generates with pnpm --filter @mapequation/c3 fixtures. They also check that the committed tutorial notebook has been executed without errors, so re-execute it after changing colors or the notebook. The notebook dependency group has what the tutorial needs, and the notebook downloads the Census state boundaries when it runs.

Metadata

Release files for c3-colors 2.0.1

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

Source distribution (sdist)

Source distribution for c3-colors 2.0.1
File Size Uploaded Provenance
c3_colors-2.0.1.tar.gz 19.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for c3-colors 2.0.1
File Interpreter ABI Platform
c3_colors-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 42.6 kB

Release files / c3_colors-2.0.1.tar.gz

Download URL c3_colors-2.0.1.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d48e0170703e4fca767418d31cbb50e79876167bb34c0bd149d9f3e3b51ce4a2
BLAKE2b-256 checksum
How to use checksums
a2331ced69633d25dacd9f54179aebdd0063fb11d8649e3c6f85913d0722ecfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / c3_colors-2.0.1-py3-none-any.whl

Download URL c3_colors-2.0.1-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
509239f50146b08a95e8efcd551041cb78b84e4126769fc693b9742d10e1159d
BLAKE2b-256 checksum
How to use checksums
83efd43c8a751211aa2fc7f4a4605f71effb7094cfdf68ec8d9b4413fa2a204b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for c3-colors 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for c3_colors-2.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files Full provenance

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