Skip to content

Reference

Cheat sheet

Every utility on one page, generated from kharita itself.

Generated from the registry by python tools/make_cheatsheet.py; do not edit by hand. Full rules in GRAMMAR.md.

A style is a space-separated list of utilities, in any order:

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

Colours are Tailwind shades (teal-600), white, black, transparent or hex in brackets ([#0f766e]), each with an optional /opacity (teal-600/70). Data goes in brackets: a column [pop], a ratio [pop/area] or a column times a number [pop*1000].

Colour by data

Utility Does Examples
fill-<colour> fill-[<expr>] Constant fill colour, or colour by data fill-indigo-600, fill-indigo-600/70, fill-white
stroke-<colour> stroke-<pixels> stroke-[<expr>] Outline or line colour, its width in pixels, or line colour by data stroke-white, stroke-slate-300/50, stroke-1
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]
null-<colour> Colour for missing values (default gray-300) null-gray-300, null-zinc-200/60

Size, lines and opacity

Utility Does Examples
size-<pixels> size-[<expr>] size-max-<pixels> Point radius in pixels, or circles sized by data (area grows with the value) size-6, size-2.5, size-[pop]
width-[<expr>] width-max-<pixels> Line or outline width by data, the widest set by width-max width-[rank], width-[flow/1000], width-max-10
dash-<on>-<off> dash-<n> Dashed lines and outlines, in line widths dash-4-2, dash-3, dash-1.5-1
opacity-<0-100> Whole-layer opacity opacity-80, opacity-0, opacity-100
highlight-<colour> Colour of the feature under the mouse highlight-amber-400, highlight-amber-400/80
halo-<colour> A soft glow around outlines, lines or points halo-cyan-300, halo-white/60
glow Colours add up where features overlap; for dark basemaps glow
mask-<colour> Cover everything outside this layer's polygons, to spotlight a site mask-white/80, mask-slate-950/60

Labels, hover and legend

Utility Does Examples
label-[<col>] Your own labels from a column, placed by the map so they never overlap; needs a kharita basemap label-[name], label-['state name']
tooltip-[<col>,<col>] Columns shown when hovering tooltip-[name], tooltip-[name,pop], tooltip-['a,b',pop]
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

3D

Utility Does Examples
extrude-[<expr>] extrude-max-<metres> 3D height from data, and the height of the tallest feature extrude-[pop], extrude-[floors*3], extrude-max-5000

Basemap

Utility Does Examples
basemap-<name> Basemap: light, dark, fiord, paper, midnight, mono, neon, topo, muted, silver, charcoal, ink, poster, satellite, hybrid, terrain, none basemap-light, basemap-dark, basemap-fiord
theme-<name> Basemap and default ramp together: paper, midnight, mono, neon, topo, silver, charcoal, ink, poster, satellite, hybrid, or one added with kh.theme theme-paper, theme-midnight, theme-mono
relief-soft relief-sharp relief-tint relief-steps Shaded terrain under a kharita basemap relief-soft, relief-sharp, relief-tint
buildings-flat buildings-3d buildings-none buildings-<colour> Basemap building footprints from zoom 13, and their colour buildings-flat, buildings-3d, buildings-none
labels-none labels-<colour> Hide or recolour the place labels of a kharita basemap labels-none, labels-slate-700

Basemap elements

Utility Does Examples
land-<colour> Colour of the basemap's ground land-stone-100, land-[#d4d4d8]
water-<colour> Colour of the basemap's sea and lakes water-sky-200, water-[#d4d4d8]
rivers-<colour> rivers-none Colour of the basemap's rivers and canals, or none to hide it rivers-sky-400, rivers-[#d4d4d8], rivers-none
parks-<colour> parks-none Colour of the basemap's parks and vegetation, or none to hide it parks-emerald-100, parks-[#d4d4d8], parks-none
roads-<colour> roads-none Colour of the basemap's major roads, or none to hide it roads-amber-200, roads-[#d4d4d8], roads-none
streets-<colour> streets-none Colour of the basemap's minor streets, or none to hide it streets-stone-200, streets-[#d4d4d8], streets-none
borders-<colour> borders-none Colour of the basemap's country borders, or none to hide it borders-slate-500, borders-[#d4d4d8], borders-none
admin-<colour> admin-none Colour of the basemap's state and province borders, or none to hide it admin-slate-300, admin-[#d4d4d8], admin-none

Reuse

Utility Does Examples
preset-<name> Expand a built-in or kh.define() style preset-choropleth, preset-outline, preset-points

Basemaps

Hosted: light, dark, fiord. Themes kharita can recolour: paper, midnight, mono, neon, topo, muted, silver, charcoal, ink, poster, satellite, hybrid. All names: light, dark, fiord, paper, midnight, mono, neon, topo, muted, silver, charcoal, ink, poster, satellite, hybrid, terrain, none.

Ramps

171 named ramps plus every Tailwind family (ramp-teal), two families (ramp-teal-rose) and your own stops (ramp-[sky-100,indigo-500]). Browse them with kh.ramps().

Presets

Preset Expands to
preset-choropleth scheme-q5 stroke-1 stroke-white null-gray-300 highlight-amber-400
preset-outline fill-transparent stroke-2 stroke-slate-700
preset-points size-4 stroke-1 stroke-white highlight-amber-400
preset-topo stroke-orange-800/80 width-[weight] width-max-1.6 legend-none

Functions

Function Does
kh.bind(data, style, colors=None, order=None) Compile a style against a table; colors and order fix category colours and their order.
kh.check_ramp(name, classes=5) Lightness steps and colour-blind safety of a ramp, at the given number of classes.
kh.colors(family=None) Every Tailwind shade kharita knows, one family per row, with each shade's number.
kh.compare(*maps, link=True) Two or more kharita maps side by side; with link, they pan and zoom together.
kh.contours(where, interval=None, zoom=None, index_every=5, detail='medium', smooth=None, below_sea=False) Contour lines over an area: a GeoDataFrame with elevation, index and weight columns.
kh.define(name, style) Save a style under a name so it can be used as preset-.
kh.explain(style) Show what a style compiles to and which token set each part.
kh.help(name=None) Print every utility, or the details and examples for one.
kh.imagery(source=2016, attribution=None, max_zoom=14) Choose the imagery for basemap-satellite and basemap-hybrid.
kh.layer(gdf, style, colors=None, order=None) Native Lonboard layers for a style: one per geometry type present.
kh.legend(gdf, style, dark=False, colors=None, order=None, **options) The legend HTML for a style on its own, for use with your own Lonboard map.
kh.map(gdf, style, legend=None, basemap=None, height=500, title=None, subtitle=None, source=None, colors=None, order=None, kicker=None, title_style=None, legend_style=None, shape=None, backdrop=None) One GeoDataFrame, one style, one map; title, subtitle and source draw the title card.
kh.palette(name, colors, kind='sequential') Register your own ramp, then use it as ramp-.
kh.parse(style) Compile a style string to a StyleSpec, raising StyleSyntaxError on any problem.
kh.ramps(kind=None, search=None, source=None, checks=True) Every ramp as a swatch strip; filter by kind, a word in the name, or source.
kh.theme(name, base='paper', ramp=None, labels=None, **elements) Register your own theme from a base theme and element colours, then use theme-.
kh.utilities() Every utility kharita understands.
kh.validate(style, columns=None) Parse a style and, if columns are given, check every referenced column exists.