Skip to content

Colour

Your own colours

Build ramps from Tailwind colours, fix category colours, and save palettes and themes to reuse.

Ramps from Tailwind colours

Write Gives
ramp-teal one family, shade 100 to 900
ramp-teal-rose diverging: teal dark to light, a neutral middle, rose light to dark
ramp-[sky-100,indigo-500,#4c1d95] your stops; blended evenly for numbers, used exactly in order for categories

Fix colours for some categories

kh.map(plants, "fill-[primary_fuel]", colors={"Coal": "zinc-700", "Solar": "yellow-300"},
       order=["Solar", "Wind", "Hydro"])

colors= gives named categories a fixed colour; the rest come from the ramp. order= sets the legend order. Both work on kh.map, Map.add, kh.layer, kh.bind and kh.legend.

Save a palette

kh.palette("brand", ["teal-700", "amber-400", "rose-600", "sky-600"], kind="categorical")
kh.map(gdf, "fill-[region] ramp-brand")

Save a theme

kh.theme("desert", base="paper", land="[#f3e5c8]", water="sky-200", ramp="lajolla")
kh.map(states, "fill-[pop] theme-desert")

A theme takes any map element colour and a default ramp. Palettes and themes last for the Python session; keep them in a module you import, next to your kh.define presets.