{"spec_id":"choropleth-basic","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nchoropleth-basic: Choropleth Map with Regional Coloring\nLibrary: altair 6.1.0 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-15\n\"\"\"\n\nimport os\n\nimport altair as alt\nfrom vega_datasets import data\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Background\" + \"Theme-adaptive Chrome\")\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Data - US unemployment rate by county\ncounties = alt.topo_feature(data.us_10m.url, \"counties\")\nunemployment = data.unemployment()\n\n# Create choropleth map\nchart = (\n    alt.Chart(counties)\n    .mark_geoshape(stroke=INK_SOFT, strokeWidth=0.5)\n    .encode(\n        color=alt.Color(\n            \"rate:Q\",\n            scale=alt.Scale(scheme=\"viridis\", domain=[0, 0.25]),\n            legend=alt.Legend(\n                title=\"Unemployment Rate\",\n                titleFontSize=20,\n                labelFontSize=16,\n                gradientLength=400,\n                gradientThickness=25,\n                titleLimit=200,\n                format=\".0%\",\n            ),\n        ),\n        tooltip=[\n            alt.Tooltip(\"id:O\", title=\"County ID\"),\n            alt.Tooltip(\"rate:Q\", title=\"Unemployment Rate\", format=\".1%\"),\n        ],\n    )\n    .transform_lookup(lookup=\"id\", from_=alt.LookupData(unemployment, \"id\", [\"rate\"]))\n    .project(type=\"albersUsa\")\n    .properties(\n        width=1600,\n        height=900,\n        title=alt.Title(\n            text=\"US County Unemployment · choropleth-basic · altair · anyplot.ai\", fontSize=44, anchor=\"middle\"\n        ),\n    )\n    .configure_view(strokeWidth=0, fill=PAGE_BG)\n    .configure_axis(\n        domainColor=INK_SOFT,\n        tickColor=INK_SOFT,\n        gridColor=INK_SOFT,\n        gridOpacity=0.10,\n        labelColor=INK_SOFT,\n        titleColor=INK,\n    )\n    .configure_title(color=INK if THEME == \"light\" else \"#FFFFFF\", fontSize=44, fontWeight=\"bold\", align=\"center\")\n    .configure_legend(\n        fillColor=ELEVATED_BG,\n        strokeColor=INK_SOFT,\n        labelColor=INK_SOFT,\n        titleColor=INK,\n        orient=\"right\",\n        offset=30,\n        padding=10,\n    )\n    .interactive()\n)\n\n# Save as PNG and HTML\nchart.save(f\"plot-{THEME}.png\", scale_factor=3.0)\nchart.save(f\"plot-{THEME}.html\")\n"}