Skip to content

Commit ccf10da

Browse files
feat(altair): implement choropleth-basic (#3106)
## Implementation: `choropleth-basic` - altair Implements the **altair** version of `choropleth-basic`. **File:** `plots/choropleth-basic/implementations/altair.py` **Parent Issue:** #3069 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20620324848)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6abe9df commit ccf10da

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
""" pyplots.ai
2+
choropleth-basic: Choropleth Map with Regional Coloring
3+
Library: altair 6.0.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-31
5+
"""
6+
7+
import altair as alt
8+
from vega_datasets import data
9+
10+
11+
# Data - US unemployment rate by county
12+
counties = alt.topo_feature(data.us_10m.url, "counties")
13+
unemployment = data.unemployment()
14+
15+
# Create choropleth map
16+
chart = (
17+
alt.Chart(counties)
18+
.mark_geoshape(stroke="white", strokeWidth=0.3)
19+
.encode(
20+
color=alt.Color(
21+
"rate:Q",
22+
scale=alt.Scale(scheme="blues", domain=[0, 0.25]),
23+
legend=alt.Legend(
24+
title="Unemployment (%)",
25+
titleFontSize=20,
26+
labelFontSize=16,
27+
gradientLength=400,
28+
gradientThickness=25,
29+
titleLimit=200,
30+
),
31+
),
32+
tooltip=[
33+
alt.Tooltip("id:O", title="County ID"),
34+
alt.Tooltip("rate:Q", title="Unemployment Rate (%)", format=".1%"),
35+
],
36+
)
37+
.transform_lookup(lookup="id", from_=alt.LookupData(unemployment, "id", ["rate"]))
38+
.project(type="albersUsa")
39+
.properties(
40+
width=1500,
41+
height=950,
42+
title=alt.Title(
43+
text="US County Unemployment · choropleth-basic · altair · pyplots.ai", fontSize=28, anchor="middle"
44+
),
45+
)
46+
.configure_view(strokeWidth=0)
47+
.configure_legend(orient="right", offset=30, padding=10)
48+
)
49+
50+
# Save as PNG and HTML
51+
chart.save("plot.png", scale_factor=3.0)
52+
chart.save("plot.html")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library: altair
2+
specification_id: choropleth-basic
3+
created: '2025-12-31T13:54:48Z'
4+
updated: '2025-12-31T14:05:55Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20620324848
7+
issue: 3069
8+
python_version: 3.13.11
9+
library_version: 6.0.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/choropleth-basic/altair/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/choropleth-basic/altair/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/choropleth-basic/altair/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent use of Altair's declarative grammar for geographic visualization with
17+
topo_feature and transform_lookup
18+
- Clean, readable code following KISS principle with proper structure
19+
- Uses real-world vega_datasets unemployment data providing authentic, meaningful
20+
visualization
21+
- Well-configured legend with appropriate font sizes and gradient dimensions
22+
- Appropriate Albers USA projection for US county-level maps
23+
- Good color scheme (blues) that is colorblind-accessible and appropriate for sequential
24+
data
25+
weaknesses:
26+
- Legend labels show decimal values (0.04, 0.08) which represent percentages but
27+
could be clearer as 4%, 8% for better readability
28+
- Missing explicit handling for missing data counties (spec suggests showing as
29+
gray)
30+
- Could leverage Altair's interactive features (.interactive() for zoom/pan or selection
31+
highlights) to better showcase library strengths

0 commit comments

Comments
 (0)