Combining geographic layers

The geographic format guide shows each layer separately. This workflow combines a continuous fill with district boundaries, district labels, and a focused extent. The result uses one GeoDataFrame throughout, so layers align without manual geometry joins or coordinate changes.

from pathlib import Path

import geopandas as gpd
import pandas as pd

from gerrytools.plotting import GeoPlot

precincts = gpd.read_file(Path("data/ga_2016_precincts.gpkg"))
precincts[["BVAP", "VAP"]] = precincts[["BVAP", "VAP"]].apply(pd.to_numeric)
precincts["BVAP_SHARE"] = precincts["BVAP"].div(precincts["VAP"])

The source rows are precincts. BVAP_SHARE is therefore calculated at precinct resolution, while the existing CD column identifies the congressional district containing each precinct. Those two columns support different layers on the same geometry.

Compose the map

The choropleth is added first and supplies the continuous fill. The plan layer is transparent inside each district, so only its dissolved boundaries and labels appear above that fill. default_outline=False avoids drawing a third, redundant outline around every source unit.

metro_mask = precincts["CTYNAME"].isin(["Clayton", "Cobb", "DeKalb", "Fulton", "Gwinnett"])

plot = GeoPlot(precincts, default_outline=False)
plot.add_choropleth_layer("BVAP_SHARE", colormap="Greys", vmin=0, vmax=1, show_colorbar=True)
plot.add_districting_plan_layer(
    "CD",
    dissolve=True,
    facealpha=0.5,
    show_labels=True,
    label_style="badge",
)
plot.focus_axes(geometry_mask=metro_mask)
plot.show()
../../../../_images/1075b456498074ef9bf4e965b1aa96b7050723e2b01b20ffb2431e384317887a.png

focus_axes() changes only the visible extent. The plot still contains every precinct and district, but the axes are fit to the five-county metro mask. The same statewide layers can therefore support a statewide map and a regional detail without creating a second, filtered GeoDataFrame.

Layer calls are stored by the builder, so the map can be revised after it renders. Adding a highlight or changing the focus marks the builder for rebuilding on the next .ax, show(), or save() call. The shared-controls guide covers those one-off adjustments.