plot_geofacet()

Visualize geographic data using a grid that roughly approximates the physical map. Each state or region is rendered as a cell with text, donut, or bar indicators.

Quick Example

import pandas as pd
import clean_charts as cc

states = [
    "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
    "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
    "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
    "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",
    "WI", "WV", "WY"
]
values = [
    42.0, 15.5, 22.0, 68.2, 98.5, 85.0, 88.4, 92.1, 74.0, 55.5, 45.0, 95.2,
    32.0, 28.5, 70.1, 35.4, 40.0, 24.5, 18.0, 94.6, 82.2, 60.0, 65.5, 58.8,
    38.0, 12.5, 20.0, 50.4, 15.0, 25.5, 72.0, 86.6, 44.4, 62.2, 96.0, 48.8,
    26.5, 90.0, 66.0, 80.5, 34.0, 22.5, 42.0, 78.5, 54.0, 76.2, 84.4, 97.5,
    52.0, 10.5, 14.0
]
df = pd.DataFrame({
    "State": states,
    "EV Adoption": values
})

cc.plot_geofacet(
    data=df,
    layout="us",
    display_type="bar",
    title="Electric Vehicle Adoption",
    subtitle="Percentage of total vehicle sales in %",
)
Geofacet
Example output for Geofacet.

Data Requirements

  • DataFrame with a column of state/region abbreviations and a column of numeric values.

Parameters

Parameter Type Default Scope Description
datapd.DataFrameBuilt-inCommonDataFrame with state abbreviations and values.
output_pathstr | NoneNoneCommonFile path to save.
widthint | NoneAutoCommonImage width in pixels.
heightint | NoneAutoCommonImage height in pixels.
aspect_ratiostr | NoneNoneCommon"square", "landscape", etc.
titlestr | NoneNoneCommonBold header text.
subtitlestr | NoneNoneCommonSecondary text.
bg_colorstr | None"#f4f3f0"CommonBackground hex color.
scale_textboolTrueCommonScale fonts proportionally.
state_colstrAutoUniqueColumn name containing location abbreviations.
value_colstrAutoUniqueColumn name containing numeric values.
layoutstr"us"UniqueGrid layout: "us", "uk".
display_typestr"text"UniqueCell render style: "text", "donut", "bar".
max_valuefloatAutoUniqueMaximum value for scaling progress rings and bars.
missing_colorstrLight grayUniqueColor for states with no data.
start_colorstr"#000000"UniqueHeatmap gradient start color.
end_colorstr"#2323FF"UniqueHeatmap gradient end color.

Common Scenarios

Donut-Style State Cells

df = pd.DataFrame({
    "State": ["CA", "TX", "NY", "FL", "IL", "PA", "OH", "GA", "NC", "MI"],
    "Goal Completion": [85, 45, 92, 38, 67, 55, 42, 60, 58, 48]
})

cc.plot_geofacet(
    data=df,
    layout="us",
    display_type="donut",
    max_value=100.0,
    title="Q3 Sales Goal Progress",
    subtitle="Percent to quota for top 10 regional markets",
    value_suffix="%",
)
Geofacet
Example output for Geofacet.

Heatmap Bar View

states = [
    "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI",
    "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
    "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
    "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA",
    "WI", "WV", "WY"
]
values = [
    42.0, 15.5, 22.0, 68.2, 98.5, 85.0, 88.4, 92.1, 74.0, 55.5, 45.0, 95.2,
    32.0, 28.5, 70.1, 35.4, 40.0, 24.5, 18.0, 94.6, 82.2, 60.0, 65.5, 58.8,
    38.0, 12.5, 20.0, 50.4, 15.0, 25.5, 72.0, 86.6, 44.4, 62.2, 96.0, 48.8,
    26.5, 90.0, 66.0, 80.5, 34.0, 22.5, 42.0, 78.5, 54.0, 76.2, 84.4, 97.5,
    52.0, 10.5, 14.0
]
df = pd.DataFrame({
    "State": states,
    "EV Adoption": values
})

cc.plot_geofacet(
    data=df,
    layout="us",
    display_type="text",
    title="Electric Vehicle Adoption",
    subtitle="Percentage of total vehicle sales in %",
    end_color="#2B0057",
    start_color="#d3a9fc"
)
Geofacet
Example output for Geofacet.