🎨 A Python utility and CLI tool for generating, previewing, and exporting colormaps.
Palettize helps create colormaps for data visualization, GIS, and web mapping. It provides a simple command-line interface to:
- Generate colormaps from a list of colors or from built-in presets.
- Preview colormaps directly in the terminal.
- Export colormaps to various formats suitable for different applications.
- Customize interpolation color space, data scaling, and slicing.
uv pip install palettizeOr install from source:
git clone https://github.com/kovaca/palettize.git
cd palettize
uv pip install .palettize --helppalettize show: Render a colormap preview in your terminal.palettize create: Export a colormap to one or more file formats.palettize list: List availablepresetsorexporters.
-
Show a built-in preset colormap:
palettize show viridis
-
Show a custom gradient made of three colors:
palettize show --colors "midnightblue,orange,gold" -
Export the 'viridis' preset to a GDAL color ramp file: The
--domainflag maps the colormap to your data's range.palettize create viridis --format gdal --output viridis_gdal.txt --domain 0,255
-
Create a custom colormap and export it to multiple formats: Use
--stepsto define the number of discrete colors in the output.palettize create -c "blue,white,red" --format qgis,mapgl \ --output "output/rwb_{format}.{ext}" --steps 11 --name "RedWhiteBlue"
This creates
output/rwb_qgis.xmlandoutput/rwb_mapgl.json. -
List all available built-in presets:
palettize list presets
-
Pass format-specific options during export: Use the
-Oor--optionflag to pass key-value pairs to an exporter.# Tell the 'observable' exporter to create a diverging scale with a pivot palettize create RdBu -f observable --domain -5,10 -o plot.json \ -O type=diverging -O pivot=0
You can also use Palettize from Python by importing the library.
from palettize import (
create_colormap,
list_available_presets,
get_scaler_by_name,
)
# Inspect presets
print(list_available_presets()[:5])
# Create from preset
cmap = create_colormap(preset="custom/grayscale", name="Grayscale", cut_start=0.1, cut_end=0.9)
print(cmap.get_color(0.5)) # hex string
print(cmap.get_color(0.5, output_format="rgb_tuple"))
# Create from a list of colors
cmap2 = create_colormap(colors=["#0000ff", "white", "#ff0000"], name="BlueWhiteRed")
# Use a scaler to map data values onto the colormap
scaler = get_scaler_by_name("symlog", domain_min=-10, domain_max=10, linthresh=1, base=10)
print(cmap2.apply_scaler(3.2, scaler))- Flexible Colormap Creation: Generate colormaps from lists of colors (hex, RGB, named) or use built-in presets.
- Advanced Interpolation: Supports various color spaces for interpolation via the ColorAide library (e.g., Oklch, sRGB, LAB).
- Terminal Preview: Instantly visualize any colormap in your terminal.
- Multiple Export Formats: Supports common formats for GIS (GDAL, QGIS, SLD, Titiler) and web (MapLibre GL, Observable Plot).
- Customizable Scaling: Apply linear, power, sqrt, or log scaling to map your data domain to the colormap.
- Plugin System for Exporters: Easily extendable with new export formats.
- CLI with Rich Output: User-friendly command-line interface with clear help messages and rich formatting.
The incredibly useful cmap library is a core dependency used for presets. To see a list of colormap presets, run:
palettize list presets
To see a list of all currently registered and available export formats, run:
palettize list exporters