Skip to content

Styling data

Classification

How values become colours: the ramp picks the colours, the scheme groups the values.

Quick reference

Utility Does Example
ramp-<name>[-r] Colour ramp for data; -r reverses it ramp-viridis
ramp-viridis-r
ramp-ylorrd
scheme-q<k>
scheme-e<k>
scheme-[b1,b2]
scheme-linear
scheme-cat
scheme-div
How data values are grouped into colour classes, or scheme-linear for none scheme-q5
scheme-e4
scheme-[10,50,100]

Schemes

Scheme Groups values Best for
scheme-q5 into 5 classes with the same number of features each (3 to 9) most choropleths; every colour gets used
scheme-e5 into 5 equal steps of the range evenly spread data; values people compare as numbers
scheme-[10,25,50] at breaks you choose thresholds that mean something, such as policy limits
scheme-linear not at all: colour runs smoothly continuous surfaces and gradients
scheme-div, scheme-div-[25] 7 symmetric classes around 0 or a value above and below an average or a target
scheme-cat one colour per value names, types, codes

Quantiles with many tied values give fewer classes, with a warning. Categories beyond twelve are grouped as "other".

Quantiles

kh.map(states, "basemap-paper fill-[density] ramp-ylorrd scheme-q5 stroke-white",
       legend={"title": "People per km2"})

No classes

kh.map(states, "basemap-paper fill-[density] scheme-linear ramp-viridis stroke-white",
       legend={"title": "People per km2"})

Your own breaks

kh.map(states, "basemap-paper fill-[density] scheme-[10,25,50] ramp-orrd stroke-white",
       legend={"title": "People per km2"})

Diverging

kh.map(states, "basemap-paper fill-[density] scheme-div-[25] ramp-heatwave stroke-white",
       legend={"title": "People per km2, centred on 25"})

scheme-div keeps the classes symmetric around the centre. On skewed data, where most values sit on one side, use your own breaks around the centre with a diverging ramp, as the US unemployment example does.

Categories

kh.map(sudan_plants, "basemap-muted fill-[primary_fuel] scheme-cat ramp-kiln size-8 stroke-white",
       colors={"Hydro": "sky-500"}, legend={"title": "Main fuel"})

Compare two schemes

kh.compare(
    kh.map(states, "basemap-paper fill-[density] ramp-ylorrd scheme-q5", legend={"title": "Quantiles"}),
    kh.map(states, "basemap-paper fill-[density] ramp-ylorrd scheme-e5", legend={"title": "Equal intervals"}),
)