Choropleth helper for GeoPandas with clean defaults for projection, layout and legend
Project description
Chorokit
Choropleth helper for GeoPandas with defaults for projection, layout and legend.
This project is in the early stages development. Contributions and feedback welcome.
Core principles
- Easy to use: the common case works with one function call or CLI command
- Defaults first, flexibility when needed: well-designed defaults that you can override with small configs; explicit beats auto
- Speed: avoid unnecessary copies and Python loops; keep plotting fast for large GeoDataFrames
- Clean, production ready outputs: consistent spacing, legible labels, subtle legend; high DPI and tight bounding boxes
- Predictable and reproducible: deterministic classifications and colors when breaks are specified; versioned defaults
- Accessible and readable: offer color-vision-safe palettes and readable tick labels
- Small surface area: dataclasses capture configuration; CLI mirrors the Python API
- Composable design: separate modules for projection, legend and layout so parts can be swapped later
Install
pip install chorokit
For development:
git clone https://github.com/mstiles/chorokit.git
cd chorokit
pip install -e .
Usage
Basic Python example
import geopandas as gpd
from chorokit import plot_choropleth
gdf = gpd.read_file("data/states.geojson")
fig, ax = plot_choropleth(
gdf=gdf,
value="value_column",
title="headline",
subtitle="subhead",
source="Source: dataset",
)
fig.savefig("out.png", dpi=300)
CLI example
chorokit data/states.geojson value_column --title "headline" --subtitle "subhead" --source "Source: dataset" -o out.png
Auto classification with top legend and projection
from chorokit import plot_choropleth, LegendConfig, LayoutConfig, Projection
legend = LegendConfig(
kind="binned",
title="value per 100k residents",
location="top",
orientation="horizontal",
scheme="quantiles",
k=5,
)
layout = LayoutConfig(title="headline", subtitle="subhead", source="Source: dataset", projection=Projection.us_albers())
fig, ax = plot_choropleth(gdf, value="value_column", cmap="Reds", legend=legend, layout=layout)
Projection override
# pass an EPSG code directly
fig, ax = plot_choropleth(gdf, value="value_column", projection=3857)
# or set in layout config
layout = LayoutConfig(projection="EPSG:3857")
fig, ax = plot_choropleth(gdf, value="value_column", layout=layout)
CLI with classification and top legend
chorokit data.geojson value_column \
--scheme quantiles -k 5 \
--legend-location top --legend-title "value per 100k"
ColorBrewer palettes
# 7-class Blues palette with natural breaks
chorokit us_states.geojson POPULATION --palette Blues:7 --scheme natural \
--title "US State Population" --source "Source: U.S. Census Bureau"
# 5-class Reds palette with quantile breaks
chorokit data.geojson value --palette Reds:5 --scheme quantiles
Python with ColorBrewer palettes
from chorokit import plot_choropleth, LegendConfig
# Use ColorBrewer palette in LegendConfig
legend = LegendConfig(
kind="binned",
palette=("Reds", 5), # 5-class Reds palette
scheme="quantiles",
title="Population density"
)
fig, ax = plot_choropleth(gdf, value="density", legend=legend)
Real-world example
import geopandas as gpd
from chorokit import plot_choropleth, LegendConfig, LayoutConfig
# Load demographic data
gdf = gpd.read_file("demographics.geojson")
# Create map with custom breaks and ColorBrewer palette
legend = LegendConfig(
kind="binned",
title="Percent of population, by block",
breaks=[0, 5, 15, 30, 50, 90],
labels=["0", "5", "15", "30", "50", "90"]
)
layout = LayoutConfig(
title="Percent non-Hispanic Asian",
subtitle="Los Angeles County blocks, 2020",
source="Source: County of Los Angeles, Census 2020"
)
fig, ax = plot_choropleth(gdf, value="pc_nh_asn", cmap="Reds", legend=legend, layout=layout)
Features
- Projection: auto-projects geographic data. Local/regional extents use a suitable UTM zone; large CONUS extents use EPSG:5070. You can pass an explicit CRS via int, EPSG string or
pyproj.CRS. - Legend: top or bottom placement; binned or continuous; auto breaks via
schemeandk; custom labels and title; professional styling - ColorBrewer palettes: access to ColorBrewer 2.0 sequential, diverging and qualitative color schemes with discrete class counts
- Theme: set font family and text sizes via
LayoutConfig.theme - CLI: flags for projection, legend options, and auto classification
ColorBrewer attribution
ColorBrewer color specifications and designs were developed by Cynthia Brewer (https://colorbrewer2.org/). Please see the ColorBrewer Apache-Style license.
Copyright 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chorokit-0.1.0.tar.gz.
File metadata
- Download URL: chorokit-0.1.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99a46261f6cbb0fb3d1eaf2eacbd4395c48e40e6c00f1c1f07b048631c3a1b7d
|
|
| MD5 |
31c633f66218d38a70b02c5a6a00eb4a
|
|
| BLAKE2b-256 |
5de8632f09382f8f08a1e1141aff0485c37ccd1a78fc29477d8eca8a9dfe06a0
|
File details
Details for the file chorokit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chorokit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e385576d5bacc6a4af0e0b650c6f74c3e6e480b64161a94972f3ee72bff528c7
|
|
| MD5 |
a9e36b148aad1ae3492b3d6e0392fff4
|
|
| BLAKE2b-256 |
288642bb5052269d75f53cf758072c5b1b4b8c4221644cdbcc905481f18926ca
|