Skip to content

Title and legend

Legends

Every layer that colours, sizes, widens or raises by data gets a legend block; one card holds them all.

Quick reference

Utility Does Example
legend-none
legend-<tl\|tc\|tr\|ml\|mr\|bl\|bc\|br>
legend-below
Hide the legend or choose where it sits: a corner, an edge centre, or below the map legend-none
legend-br
legend-tc

Options

legend= takes what the legend says; legend_style= takes how it looks and where it sits.

legend= key Does
title the heading; defaults to the column or expression
fmt a number format for class edges, such as "{:,.0f}" or "{:.0%}"
labels your own text, one per class (two or three ticks for scheme-linear)
note a small line under the block
style "list" (default) or "bar", a compact bar with the edges under it
counts False hides the class counts

A bar legend

kh.map(states, "basemap-paper fill-[pop] ramp-teal scheme-q5 stroke-white",
       legend={"title": "Population", "style": "bar"})

Anywhere on the map

Eight places inside the map, plus below. The legend- utility picks a place in the style string; legend_style= can also set it, and wins.

kh.map(states, "theme-paper fill-[density] ramp-ylorrd scheme-q5 stroke-white",
       title="Population density", title_style="top-center text-2xl",
       legend={"style": "bar"}, legend_style="bottom-center bg-white/80 bg-blur")

Glass

kh.map(states, "theme-midnight fill-[density] ramp-viridis scheme-q5",
       legend={"title": "People per km2"},
       legend_style="middle-right bg-slate-900/40 bg-blur text-white border-white/20 rounded-2xl")

Keys added for you

Layer uses Key
size-[...] three nested circles with their values
width-[...] three line samples
extrude-[...] a height note: what height shows and how tall the tallest is
scheme-linear a gradient with low, middle and high ticks

Your own Lonboard map

kh.legend(gdf, style, title="Population") returns the legend card as HTML to place yourself.