Skip to content

Getting started

Your first map

From a GeoDataFrame to a finished, titled map in four steps.

The examples on this site use Sudan's 18 states with their 2008 census population, which ships with kharita's repository in data/processed/sudan_states.gpkg. It has the columns key, pop, area_km2 and density.

import geopandas as gpd
import kharita as kh

states = gpd.read_file("data/processed/sudan_states.gpkg")

1. One colour

A style string is a list of utilities separated by spaces. Colours are Tailwind names with an optional opacity after a slash.

kh.map(states, "basemap-paper fill-teal-600/60 stroke-white stroke-1")

2. Colour by data

Put a column in brackets. kharita classifies it, here into five quantile classes, colours each class from a ramp and writes the legend with the count in each class.

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

3. A theme and a ratio

theme-paper swaps the basemap for a warm print style and puts place names above your data. Brackets also take a ratio of two columns.

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

4. Title, subtitle and source

Text goes in keyword arguments, not the style string.

kh.map(states, "theme-paper fill-[density] ramp-ylorrd scheme-q5 stroke-white",
       title="Population density", subtitle="Sudan by state, 2008 census",
       source="U.S. Census Bureau via HDX")

Share it

m = kh.map(states, "theme-paper fill-[density] ramp-ylorrd scheme-q5", title="Population density")
m.to_html("density.html")

Next: Core concepts explains how styles, layers and maps fit together.