Skip to content

Color Interpolation

When creating colormaps, the choice of color space for interpolation significantly affects how colors blend between stops. Palettize supports multiple interpolation spaces via the ColorAide library.

Consider a gradient from blue to yellow:

  • sRGB interpolation: May produce muddy greens in the middle
  • Oklch interpolation: Produces vibrant, perceptually uniform transitions

The interpolation space determines the path colors take through color space when blending.

Oklch is a perceptually uniform color space based on human vision. It provides:

  • Consistent perceived brightness across the gradient
  • Vibrant, natural-looking color transitions
  • No unexpected muddy colors
Terminal window
palettize show --colors "blue,yellow" --space oklch

This is the default and recommended for most use cases.

Standard RGB interpolation. Colors blend in the same space as computer displays.

Terminal window
palettize show --colors "blue,yellow" --space srgb

Characteristics:

  • Fast computation
  • May produce muddy/desaturated midpoints
  • Common in web/CSS gradients

A perceptually uniform color space from 1976.

Terminal window
palettize show --colors "blue,yellow" --space lab

Characteristics:

  • Good perceptual uniformity
  • Better than sRGB for scientific visualization
  • May produce some hue shifts

Cylindrical representation of LAB, using Hue, Chroma, and Lightness.

Terminal window
palettize show --colors "blue,yellow" --space hcl

Characteristics:

  • Intuitive hue interpolation
  • Good for rainbow-like gradients
  • May have chroma issues at extreme values

Hue, Saturation, Lightness - a common web color model.

Terminal window
palettize show --colors "blue,yellow" --space hsl

Characteristics:

  • Intuitive for designers
  • Non-uniform perceptually
  • Can produce unexpected results
Terminal window
# Compare the same gradient in different spaces
palettize show --colors "blue,yellow" --space srgb --height 2
palettize show --colors "blue,yellow" --space oklch --height 2
palettize show --colors "blue,yellow" --space lab --height 2
from palettize import create_colormap
colors = ["blue", "yellow"]
for space in ["srgb", "oklch", "lab", "hcl"]:
cmap = create_colormap(colors=colors, interpolation_space=space)
midpoint = cmap.get_color(0.5)
print(f"{space}: {midpoint}")

Output:

srgb: #808000
oklch: #a3b852
lab: #9ab356
hcl: #8cb866

Notice how sRGB produces a darker, muddier olive color while the perceptual spaces produce brighter, more vibrant midpoints.

  • Creating scientific visualizations
  • You want perceptually uniform brightness
  • Working with diverging colormaps
  • Default choice for most applications
  • Matching existing CSS/web gradients
  • Performance is critical
  • You specifically need RGB blending behavior
  • Porting from tools that use these spaces
  • Working with color science applications
  • Creating perceptually balanced palettes

The interpolation space affects the colors sampled during export:

from palettize import create_colormap, get_scaler_by_name, get_exporter
cmap_srgb = create_colormap(colors=["blue", "yellow"], interpolation_space="srgb")
cmap_oklch = create_colormap(colors=["blue", "yellow"], interpolation_space="oklch")
scaler = get_scaler_by_name("linear", domain_min=0, domain_max=1)
exporter = get_exporter("hex")
# Different midpoint colors
print(exporter.export(cmap_srgb, scaler, 0, 1, {"num_colors": 3}))
print(exporter.export(cmap_oklch, scaler, 0, 1, {"num_colors": 3}))
  1. Start with Oklch: It’s the default for good reason
  2. Test visually: Use palettize show to preview before exporting
  3. Consider your data: Scientific data often benefits from perceptually uniform spaces
  4. Be consistent: Use the same space throughout a project

A “perceptually uniform” color space means equal numeric changes produce equal perceived changes in color.

In sRGB:

  • Changing R from 100→150 might look very different from 150→200
  • The same numeric difference produces different perceived differences

In Oklch:

  • Equal steps in lightness produce equal perceived brightness changes
  • Colors blend more naturally

This is especially important for data visualization where color represents numeric values.

SpaceTypePerceptualHue Handling
srgbRGBNoN/A
oklchCylindricalYesExcellent
labRectangularYesGood
hclCylindricalYesGood
hslCylindricalNoDirect
hsvCylindricalNoDirect
okhslCylindricalYesGood
okhsvCylindricalYesGood

Palettize supports any color space that ColorAide supports. See the ColorAide documentation for the full list.