Shared geographic plot controls¶
GeoPlot and DotDensityPlot share controls for outlines, focus, labels, colorbars,
and output. Each example below changes one behavior.
from pathlib import Path
import geopandas as gpd
import pandas as pd
from gerrytools.plotting import GeoPlot, LabelOptions
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"])
Outlines¶
add_outline_layer() accepts the base GeoDataFrame, a separate geographic source, or a
boolean mask. Supplying dissolve_column= converts finer source units into the boundaries of
a larger geography before drawing.
outlines = GeoPlot(precincts)
outlines.add_outline_layer(dissolve_column="CTYNAME")
outlines.show()
Focus¶
focus_axes() changes the axes limits without removing any layer data. Its default padding is
two percent of the selected geometry’s width and height; pad= accepts one value, separate x
and y values, or four side-specific values.
metro_mask = precincts["CTYNAME"].isin(["Clayton", "Cobb", "DeKalb", "Fulton", "Gwinnett"])
focused = GeoPlot(precincts)
focused.add_districting_plan_layer("CD")
focused.focus_axes(geometry_mask=metro_mask)
focused.show()
Labels¶
District and outline layers can calculate one label position per dissolved geography. Named
styles cover the common treatments: "halo", "badge", "ink", "plain", and
"tag". Start with a named label style, then use LabelOptions only for adjustments that
the style does not cover.
labeled = GeoPlot(precincts)
labeled.add_districting_plan_layer(
"CD",
dissolve=True,
show_labels=True,
label_options=LabelOptions(label_style="badge"),
)
labeled.show()
Colorbars¶
A choropleth returns a layer handle. show_colorbar=True attaches a colorbar immediately;
add_colorbar(layer) can attach one later to the same scale. This matters when a map contains
several continuous layers and only selected layers need keys.
shares = GeoPlot(precincts)
shares.add_choropleth_layer("BVAP_SHARE", show_colorbar=True)
shares.show()
Output¶
show() displays the current map and save() writes the same rendered state. Pass title=
when constructing the plot or assign .title later; set_title_style() provides the same
styling controls as the statistical builders. SVG and PDF preserve vector boundaries for
reports; PNG is useful when the final destination requires a raster image. The builder’s .ax
remains available for Matplotlib-level composition.
shares.save("bvap-share.svg")
Advanced label placement¶
LabelOptions can adjust individual labels without replacing the named label style. The
adjustments mapping uses the displayed label as its key and an (x, y) offset as its value.
Offsets are measured in the map’s coordinate units, so their useful magnitude depends on the
active projected coordinate reference system.
adjusted = GeoPlot(precincts)
adjusted.add_districting_plan_layer(
"CD",
dissolve=True,
show_labels=True,
label_options=LabelOptions(
label_style="badge",
adjustments={5: (-60_000, -25_000), 6: (0, 25_000)},
),
)
adjusted.show()