Colors and Colormaps¶
This page covers practical usage: picking colors, mixing them, interpolating gradients, and using colormaps. For full visual catalogs of every palette and colormap, see the Color System reference.
Named colors¶
dartwork-mpl registers named palettes from OpenColor, Tailwind, Material, Ant Design, Chakra, and Primer. Use them anywhere matplotlib accepts a color.
Prefix |
Library |
Example |
|---|---|---|
|
OpenColor |
|
|
Tailwind CSS |
|
|
Material Design |
|
|
Ant Design |
|
|
Chakra UI |
|
|
Primer |
|
import matplotlib.pyplot as plt
import dartwork_mpl as dm
import numpy as np
dm.style.use("presentation")
fig, ax = plt.subplots(figsize=(dm.cm2in(8), dm.cm2in(5)), dpi=300)
ax.plot([0, 1, 2], [1, 2, 1.5], marker="o", color="oc.green5", label="oc.*")
ax.plot([0, 1, 2], [1.2, 1.6, 2.1], marker="s", color="tw.blue500", label="Tailwind")
highlight = dm.mix_colors("md.orange600", "white", alpha=0.45)
ax.fill_between([0, 1, 2], 0.9, 1.3, color=highlight, label="Mixed shade")
muted_line = dm.pseudo_alpha("pr.blue5", alpha=0.65, background="white")
ax.plot([0, 1, 2], [0.8, 1.1, 1.4], color=muted_line, label="Pseudo alpha")
ax.legend(fontsize=dm.fs(-1))
dm.simple_layout(fig)
Color class¶
For most plots, named color strings like "oc.blue5" are all you need. When
you need to programmatically adjust hue, saturation, or lightness — or
interpolate between colors in a perceptually uniform space — use the Color
class:
import dartwork_mpl as dm
color = dm.oklch(0.7, 0.15, 150) # OKLCH (L, C, h°)
color.oklch.C *= 1.2 # boost chroma in-place
print(color.to_hex()) # '#...'
→ Full guide: Color Space & Manipulation — constructors, views, interpolation, and custom colormaps.
Exploring Available Colors¶
dartwork-mpl provides utilities to discover and explore available color palettes:
import dartwork_mpl as dm
# List all discrete color palettes
palettes = dm.list_palettes()
print(palettes[:5]) # ['dc.vivid', 'oc.blue', 'oc.red', 'tw.emerald', ...]
# List all colormaps
cmaps = dm.list_colormaps()
print(cmaps[:5]) # ['dc.deep_sea', 'dc.forest', 'dc.sunset', ...]
# Preview a specific palette
dm.show_palette('oc.blue') # Shows all shades: blue0, blue1, ..., blue9
# Visualize multiple palettes at once
dm.plot_colors(['oc.blue', 'tw.emerald', 'md.purple'])
# Visualize colormaps
dm.plot_colormaps(['dc.deep_sea', 'dc.forest'])
# Classify a colormap by type
cmap_type = dm.classify_colormap('viridis')
print(cmap_type) # 'sequential'
Color interpolation¶
import dartwork_mpl as dm
# Perceptual interpolation between colors (OKLCH by default)
palette = dm.cspace('#FF6B6B', '#4ECDC4', n=5, space='oklch')
for i, c in enumerate(palette):
ax.bar(i, 1, color=c.to_hex())
# Also supports 'oklab' and 'rgb' spaces
gradient = dm.cspace(dm.named('oc.red5'), dm.named('oc.blue5'), n=10)
Why OKLCH matters: Interpolating in RGB produces muddy, desaturated midtones. OKLCH maintains perceptual uniformity — every step looks equally spaced to the human eye:
Colormaps¶
dartwork-mpl bundles custom colormaps prefixed with dc. — curated for
perceptually uniform gradients. They work like any matplotlib colormap:
import matplotlib.pyplot as plt
import dartwork_mpl as dm
cmap = plt.colormaps["dc.deep_sea"]
print(cmap.name) # 'dc.deep_sea'
print(dm.classify_colormap(cmap)) # 'sequential' (tells you the type)
Add _r to reverse any colormap (e.g., dc.sunset_r). Browse all available
colormaps on the Colormaps page.
Where things live¶
Color sources:
asset/color/*.txt+ Tailwind/Material/Ant/Chakra/Primer/opencolor JSONPalette/colormap previews: Color System
API functions: Color Utilities and Visualization Tools