# How to Make a Choropleth Map in Python with GeoPandas

> Make a choropleth map in Python with GeoDataFrame.plot(): merge data onto shapes, fix the projection, bin values, label states, add Alaska and Hawaii, and map the world.

Source: https://www.pythoncharts.com/python/choropleth-map-geopandas/ | Published: 2026-11-26 | Author: Alex Scott | Category: Python | Tags: python, matplotlib, choropleth, geopandas, map, geospatial

To make a choropleth map in Python, load region shapes with `geopandas.read_file()`, merge your data onto them, and call `.plot(column="your_value", legend=True)`. [GeoPandas](https://geopandas.org/) draws the map with Matplotlib, so the usual axes, colormap, and colorbar tools apply.

Install the packages with `pip install geopandas matplotlib mapclassify`. The examples use GeoPandas 1.2.0.

## Quick Example

This maps net domestic migration (people arriving from other states minus people leaving) per 1,000 residents. Both files come from the US Census Bureau: [state boundaries](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html) and the [Vintage 2025 population estimates](https://www.census.gov/programs-surveys/popest.html).

```python
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.colors import TwoSlopeNorm

shapes = gpd.read_file(
    "https://www2.census.gov/geo/tiger/GENZ2024/shp/cb_2024_us_state_20m.zip")
pop = pd.read_csv(
    "https://www2.census.gov/programs-surveys/popest/datasets/"
    "2020-2025/state/totals/NST-EST2025-ALLDATA.csv")

# keep state rows and format the state code like the shapefile's ("06", not 6)
pop = pop[pop["SUMLEV"] == 40].copy()
pop["STATEFP"] = pop["STATE"].astype(str).str.zfill(2)

states = shapes.merge(pop[["STATEFP", "RDOMESTICMIG2025", "POPESTIMATE2025"]],
                      on="STATEFP", how="left")
lower48 = states[~states["STUSPS"].isin(["AK", "HI", "PR"])].to_crs("EPSG:5070")

norm = TwoSlopeNorm(vcenter=0, vmin=-8, vmax=13)

fig, ax = plt.subplots(figsize=(10, 6))
lower48.plot(column="RDOMESTICMIG2025", cmap="BrBG", norm=norm,
             edgecolor="white", linewidth=0.6, legend=True,
             legend_kwds={"label": "Net domestic migration per 1,000 residents",
                          "orientation": "horizontal", "shrink": 0.6, "pad": 0.02},
             ax=ax)
ax.set_title("Where Americans moved, July 2024 to July 2025", fontsize=14)
ax.axis("off")
plt.show()
```

![Choropleth map of the contiguous United States showing 2025 net domestic migration. South Carolina, Idaho and North Carolina are dark teal for gains; New York, California and Massachusetts are brown for losses](https://www.pythoncharts.com/python/choropleth-map-geopandas/images/choropleth-map-geopandas-quick-example.png)

South Carolina gained the most (+12.0 per 1,000), followed by Idaho (+9.9) and North Carolina (+7.6). New York lost the most (-6.9). Across the 50 states and DC, 31 gained residents from elsewhere in the country and 20 lost them.

Because the data has a meaningful zero, the map uses a diverging colormap, and `TwoSlopeNorm(vcenter=0)` pins the neutral color to zero even though the gains reach further than the losses. For data that only goes up from zero, such as population density, use a sequential colormap like `"viridis"` or `"Blues"`.

## Merge Data onto a GeoDataFrame

A choropleth needs one row per region with both a `geometry` column and the value to color by. Most problems happen in the merge:

- **Call `merge()` on the GeoDataFrame.** `shapes.merge(data)` returns a GeoDataFrame. `data.merge(shapes)` returns a plain DataFrame without the `.plot()` map method.
- **Match key types.** The shapefile stores state codes as zero-padded strings, while `read_csv()` reads them as integers. That is what `str.zfill(2)` fixes.
- **Use `how="left"`** so regions without data stay on the map, then check for gaps with `states["RDOMESTICMIG2025"].isna().sum()`.

`read_file()` also reads GeoJSON, GeoPackage, and local shapefiles. To work offline, download the zip file once and pass its path.

## Fix a Stretched Map with to_crs()

The Census shapes are stored as latitude and longitude (EPSG:4269). Plotting those directly makes the northern border a straight line and distorts areas. Reproject with `to_crs()` before plotting. EPSG:5070 is an Albers equal-area projection made for the contiguous US:

```python
fig, axes = plt.subplots(1, 2, figsize=(11, 4))
for ax, crs, title in zip(axes, ["EPSG:4269", "EPSG:5070"],
                          ["EPSG:4269 (latitude and longitude)",
                           "EPSG:5070 (Albers equal area)"]):
    lower48.to_crs(crs).plot(color="#d8e2dc", edgecolor="#44576d", linewidth=0.5, ax=ax)
    ax.set_title(title, fontsize=11)
    ax.axis("off")
fig.tight_layout()
plt.show()
```

![The contiguous United States in latitude and longitude, with a flat northern border, next to the Albers projection, with a curved northern border](https://www.pythoncharts.com/python/choropleth-map-geopandas/images/choropleth-projections.png)

An equal-area projection matters for choropleths, since readers judge how much of the map has each color.

## Bin Values and Label Regions

With a continuous color scale, similar values are hard to tell apart. The `scheme` argument groups them into classes using the [mapclassify](https://pysal.org/mapclassify/) package. `scheme="quantiles"` with `k=5` puts about the same number of states in each class. `"naturalbreaks"` and `"equalinterval"` are common alternatives.

To label regions, use `representative_point()`, which always falls inside the shape. A `centroid` can land outside a curved or multi-part region.

```python
fig, ax = plt.subplots(figsize=(10, 6.5))
lower48.plot(column="RDOMESTICMIG2025", cmap="PuBuGn", scheme="quantiles", k=5,
             edgecolor="#555555", linewidth=0.4, legend=True,
             legend_kwds={"loc": "lower left", "title": "Per 1,000 residents",
                          "fmt": "{:.1f}", "frameon": False, "fontsize": 9},
             ax=ax)

for row in lower48.nlargest(3, "RDOMESTICMIG2025").itertuples():
    point = row.geometry.representative_point()
    ax.annotate(f"{row.STUSPS}\n{row.RDOMESTICMIG2025:+.1f}", (point.x, point.y),
                ha="center", va="center", fontsize=8, fontweight="bold",
                bbox=dict(facecolor="white", alpha=0.85, edgecolor="none", pad=1.5))
ax.set_title("Net domestic migration, in five equal-sized groups", fontsize=14)
ax.axis("off")
plt.show()
```

![US choropleth with five quantile classes from -6.9 to 12.0, with South Carolina, Idaho and North Carolina labeled with their values](https://www.pythoncharts.com/python/choropleth-map-geopandas/images/choropleth-quantiles-labels.png)

`legend_kwds` takes different keys depending on the map. With `scheme`, it configures a Matplotlib legend (`loc`, `title`, `fmt`). Without it, it configures the [colorbar](https://www.pythoncharts.com/matplotlib/matplotlib-colorbar/) (`label`, `shrink`, `orientation`).

## Add Alaska and Hawaii as Insets

Plot each of the two states on its own [inset axes](https://matplotlib.org/stable/gallery/subplots_axes_and_figures/zoom_inset_axes.html), with a projection suited to it. Passing the same `norm` to every call keeps the colors comparable.

```python
fig, ax = plt.subplots(figsize=(10, 6.5))
style = dict(column="RDOMESTICMIG2025", cmap="BrBG", norm=norm,
             edgecolor="white", linewidth=0.5)
lower48.plot(ax=ax, **style)

ak_ax = ax.inset_axes([-0.02, -0.04, 0.25, 0.28])
states[states["STUSPS"] == "AK"].to_crs("EPSG:3338").plot(ax=ak_ax, **style)

hi_ax = ax.inset_axes([0.22, -0.02, 0.15, 0.17])
states[states["STUSPS"] == "HI"].to_crs("ESRI:102007").plot(ax=hi_ax, **style)

for a in (ax, ak_ax, hi_ax):
    a.axis("off")

fig.colorbar(plt.cm.ScalarMappable(norm=norm, cmap="BrBG"), ax=ax, shrink=0.6,
             label="Net domestic migration per 1,000")
ax.set_title("All 50 states and DC", fontsize=14)
plt.show()
```

![US migration choropleth with Alaska and Hawaii inset at the lower left, both brown, showing net losses](https://www.pythoncharts.com/python/choropleth-map-geopandas/images/choropleth-alaska-hawaii.png)

The insets aren't drawn to the same scale as the main map.

## World Choropleth with Missing Data

[Natural Earth](https://www.naturalearthdata.com/) provides public domain country shapes that include population and GDP estimates. GDP per capita spans a wide range, so a logarithmic color scale (`LogNorm`) works better than a linear one. `missing_kwds` styles countries with no value, which here means those whose GDP estimate is older than 2018.

```python
from matplotlib.colors import LogNorm
from matplotlib.ticker import FuncFormatter

world = gpd.read_file(
    "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")
world = world[world["ADMIN"] != "Antarctica"].to_crs("EPSG:8857")
world["gdp_per_capita"] = world["GDP_MD"].astype("float64") * 1_000_000 / world["POP_EST"]
world.loc[world["GDP_YEAR"] < 2018, "gdp_per_capita"] = float("nan")

fig, ax = plt.subplots(figsize=(11, 5.8))
world.plot(column="gdp_per_capita", cmap="magma_r",
           norm=LogNorm(vmin=250, vmax=120_000),
           edgecolor="white", linewidth=0.3, legend=True,
           legend_kwds={"label": "GDP per capita (US$, log scale)", "shrink": 0.7,
                        "orientation": "horizontal", "pad": 0.02,
                        "format": FuncFormatter(lambda v, _: f"${v:,.0f}")},
           missing_kwds={"color": "#d9d9d9", "hatch": "///"},
           ax=ax)
ax.set_title("GDP per capita from Natural Earth estimates (mostly 2019)", fontsize=14)
ax.axis("off")
plt.show()
```

![World choropleth of GDP per capita on a log scale. North America, Western Europe and Australia are darkest, much of sub-Saharan Africa is lightest, and a few countries are hatched grey for old data](https://www.pythoncharts.com/python/choropleth-map-geopandas/images/choropleth-world-map.png)

Two things to watch with this file:

- `GDP_MD` (GDP in millions) is a 32-bit integer column. Multiplying it by 1,000,000 without `astype("float64")` overflows silently and produces nonsense, including negative values.
- `ISO_A3` is `-99` for France, Norway, and a few others. Join your own country data on `ADM0_A3` instead.

## GeoPandas or Plotly for Choropleth Maps?

| Use | When |
|---|---|
| GeoPandas | Static maps for reports and papers, custom boundaries, projections, and spatial joins |
| [Plotly's `px.choropleth()`](https://www.pythoncharts.com/plotly/plotly-geo-maps/) | Interactive maps with hover tooltips, especially of countries or US states with built-in shapes |

A choropleth works best for rates and ratios. Coloring regions by a raw count mostly shows where people live, and large, sparsely populated areas dominate the picture.

For a pannable web map with markers and layers, see [interactive maps with Folium](https://www.pythoncharts.com/python/folium-maps-python/).

## Similar Topics

- [Geospatial maps in Plotly](https://www.pythoncharts.com/plotly/plotly-geo-maps/)
- [Add and customize a colorbar in Matplotlib](https://www.pythoncharts.com/matplotlib/matplotlib-colorbar/)
- [Create custom colormaps in Matplotlib](https://www.pythoncharts.com/matplotlib/matplotlib-custom-colormaps/)
