Skip to content

Commit c312751

Browse files
update(area-basic): altair — comprehensive quality review (#4175)
## Summary Updated **altair** implementation for **area-basic**. ### Changes - Added traffic spike mid-month (marketing campaign) - Added interactive tooltips (date + visitors) - Moved axis font config to configure_axis() for cleaner code - Improved axis label with units "(count)" ## Test Plan - [x] Preview images uploaded to GCS staging - [x] Implementation file passes ruff format/check - [x] Metadata YAML updated with current versions - [ ] Automated review triggered --- Generated with [Claude Code](https://claude.com/claude-code) `/update` command --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 195bbc7 commit c312751

2 files changed

Lines changed: 94 additions & 85 deletions

File tree

plots/area-basic/implementations/altair.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyplots.ai
22
area-basic: Basic Area Chart
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: altair 6.0.0 | Python 3.14.2
4+
Quality: 95/100 | Created: 2025-12-23
55
"""
66

77
import altair as alt
@@ -18,6 +18,8 @@
1818
weekly_pattern = np.array([1.2, 1.1, 1.0, 1.05, 1.15, 0.8, 0.7] * 5)[:30]
1919
noise = np.random.randn(30) * 300
2020
visitors = (base + trend) * weekly_pattern + noise
21+
# Add a traffic spike mid-month (e.g., marketing campaign on Jan 15)
22+
visitors[14] *= 1.4
2123
visitors = np.maximum(visitors, 1000).astype(int)
2224

2325
df = pd.DataFrame({"date": dates, "visitors": visitors})
@@ -27,20 +29,19 @@
2729
alt.Chart(df)
2830
.mark_area(opacity=0.4, color="#306998", line={"color": "#306998", "strokeWidth": 3})
2931
.encode(
30-
x=alt.X("date:T", title="Date", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
31-
y=alt.Y(
32-
"visitors:Q",
33-
title="Daily Visitors",
34-
scale=alt.Scale(domain=[0, df["visitors"].max() * 1.1]),
35-
axis=alt.Axis(labelFontSize=18, titleFontSize=22),
36-
),
32+
x=alt.X("date:T", title="Date"),
33+
y=alt.Y("visitors:Q", title="Daily Visitors (count)", scale=alt.Scale(domain=[0, df["visitors"].max() * 1.1])),
34+
tooltip=[
35+
alt.Tooltip("date:T", title="Date", format="%b %d, %Y"),
36+
alt.Tooltip("visitors:Q", title="Visitors", format=","),
37+
],
3738
)
3839
.properties(width=1600, height=900, title=alt.Title("area-basic · altair · pyplots.ai", fontSize=28))
39-
.configure_axis(grid=True, gridOpacity=0.3, gridDash=[4, 4])
40+
.configure_axis(grid=True, gridOpacity=0.3, gridDash=[4, 4], labelFontSize=18, titleFontSize=22)
4041
.configure_view(strokeWidth=0)
4142
)
4243

43-
# Save as PNG (1600 × 900 × 3 = 4800 × 2700 px)
44+
# Save as PNG (1600 × 900 at scale_factor=3 → 4800 × 2700 px)
4445
chart.save("plot.png", scale_factor=3.0)
4546

4647
# Save interactive HTML version
Lines changed: 82 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,216 @@
11
library: altair
22
specification_id: area-basic
33
created: '2025-12-23T00:47:41Z'
4-
updated: '2025-12-23T01:21:39Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-11T22:27:06Z'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20447969752
77
issue: 0
8-
python_version: 3.13.11
8+
python_version: 3.14.2
99
library_version: 6.0.0
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/area-basic/altair/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/area-basic/altair/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/area-basic/altair/plot.html
13-
quality_score: 91
13+
quality_score: 95
1414
impl_tags:
1515
dependencies: []
16-
techniques: []
16+
techniques:
17+
- hover-tooltips
18+
- html-export
1719
patterns:
18-
- data-generation
19-
dataprep: []
20+
- data-generation
21+
dataprep:
22+
- time-series
2023
styling:
21-
- alpha-blending
22-
- grid-styling
24+
- alpha-blending
25+
- grid-styling
2326
review:
2427
strengths:
25-
- Excellent weekly pattern simulation showing realistic website traffic with weekday
26-
peaks and weekend dips
27-
- Clean declarative Altair code following the library's grammar of graphics philosophy
28-
- Good use of opacity (0.4) and line styling to create visual depth
29-
- Proper use of temporal encoding (:T) for dates
30-
- Generates both PNG and interactive HTML versions
28+
- Excellent data generation with realistic weekly patterns, growth trend, and a
29+
traffic spike event that showcases the area chart ability to highlight volume
30+
changes
31+
- Clean, well-proportioned layout with the plot filling the canvas effectively
32+
- Proper use of Altair declarative grammar including typed encodings, tooltip formatting,
33+
and scale configuration
34+
- Includes both PNG and interactive HTML output, leveraging Altair web-native capabilities
35+
- Semi-transparent fill (0.4) with solid line border creates clear visual distinction
36+
between the area and the line
3137
weaknesses:
32-
- Y-axis label could include units (e.g., Daily Visitors (count))
33-
- Could add tooltip showing exact values for interactive version carried to static
34-
aesthetics
38+
- The first x-axis tick label shows 2024 instead of a formatted date — a minor Altair
39+
temporal axis default that slightly breaks the consistent date label pattern
40+
- No gradient fill from line to axis baseline, which the spec suggests considering
41+
for visual appeal
42+
- Could leverage more distinctive Altair features like selection parameters or layered
43+
marks (e.g., a point mark layer for individual data points on hover)
3544
image_description: The plot displays a basic area chart showing daily website visitors
36-
over January 2024 (30 days). The area is filled with a semi-transparent blue color
37-
(#306998) with a darker blue line along the top edge. The title "area-basic ·
38-
altair · pyplots.ai" is centered at the top in black text. The X-axis shows "Date"
39-
with date labels (2024, Wed 03, Fri 05, etc.), and the Y-axis shows "Daily Visitors"
40-
ranging from 0 to approximately 8,500. Dashed gridlines are visible throughout.
41-
The data shows a clear weekly pattern with dips on weekends (Saturday/Sunday)
42-
and higher values on weekdays, plus an overall upward trend from ~6,000 to ~7,500
43-
visitors.
45+
over January 2024 (30 data points). The area is filled with a semi-transparent
46+
blue (#306998, opacity 0.4) with a solid blue line border (strokeWidth 3). The
47+
x-axis shows dates labeled with day-of-week abbreviations and day numbers (e.g.,
48+
"Wed 03", "Fri 05"), with the first tick showing "2024". The y-axis ranges from
49+
0 to approximately 10,000 and is labeled "Daily Visitors (count)". The title "area-basic
50+
· altair · pyplots.ai" is displayed at the top in a large font. Subtle dashed
51+
gridlines are visible across the chart area. The data shows clear weekly cyclical
52+
patterns (weekday highs around 5,500-7,500, weekend dips around 3,500-5,000),
53+
a visible upward growth trend across the month, and a prominent traffic spike
54+
around January 15 reaching approximately 9,400 visitors. The layout is clean and
55+
well-proportioned with balanced margins.
4456
criteria_checklist:
4557
visual_quality:
46-
score: 36
58+
score: 38
4759
max: 40
4860
items:
4961
- id: VQ-01
5062
name: Text Legibility
5163
score: 9
5264
max: 10
5365
passed: true
54-
comment: All text is readable; title at 28pt, axis labels at 22pt, tick labels
55-
at 18pt. Slightly conservative sizing but fully legible.
66+
comment: 'Title 28pt, axis labels 22pt, ticks 18pt. All clearly readable.
67+
Minor: first x-axis tick shows ''2024'' instead of formatted date.'
5668
- id: VQ-02
5769
name: No Overlap
5870
score: 8
5971
max: 8
6072
passed: true
61-
comment: No overlapping text elements anywhere
73+
comment: No overlapping text elements. X-axis date labels well-spaced.
6274
- id: VQ-03
6375
name: Element Visibility
64-
score: 8
76+
score: 7
6577
max: 8
6678
passed: true
67-
comment: Area fill with 0.4 opacity and 3px line width is well-suited for
68-
this data density (30 points)
79+
comment: Area fill and line clearly visible. Line width of 3 works well for
80+
30 data points.
6981
- id: VQ-04
7082
name: Color Accessibility
7183
score: 5
7284
max: 5
7385
passed: true
74-
comment: Single blue color (#306998), no color comparison needed, good contrast
86+
comment: Single blue series on white. Fully colorblind-safe.
7587
- id: VQ-05
7688
name: Layout Balance
77-
score: 4
89+
score: 5
7890
max: 5
7991
passed: true
80-
comment: Good proportions, slight excess whitespace in lower portion due to
81-
Y-axis starting at 0
92+
comment: Excellent canvas utilization with balanced margins.
8293
- id: VQ-06
8394
name: Axis Labels
84-
score: 1
95+
score: 2
8596
max: 2
8697
passed: true
87-
comment: Descriptive labels ("Date", "Daily Visitors") but no units
98+
comment: Date on x-axis, Daily Visitors (count) on y-axis. Descriptive with
99+
units.
88100
- id: VQ-07
89101
name: Grid & Legend
90-
score: 1
102+
score: 2
91103
max: 2
92104
passed: true
93-
comment: Grid is subtle with dashed lines and 0.3 opacity; no legend needed
94-
for single series
105+
comment: Dashed gridlines with opacity 0.3 are subtle and helpful. No legend
106+
needed.
95107
spec_compliance:
96-
score: 25
108+
score: 24
97109
max: 25
98110
items:
99111
- id: SC-01
100112
name: Plot Type
101113
score: 8
102114
max: 8
103115
passed: true
104-
comment: Correct area chart with filled area below the line
116+
comment: Correct area chart using mark_area().
105117
- id: SC-02
106118
name: Data Mapping
107119
score: 5
108120
max: 5
109121
passed: true
110-
comment: X=datetime (date), Y=numeric (visitors) correctly mapped
122+
comment: X is temporal (dates), Y is quantitative (visitors).
111123
- id: SC-03
112124
name: Required Features
113-
score: 5
125+
score: 4
114126
max: 5
115127
passed: true
116-
comment: Semi-transparent fill (0.4), gridlines, clear axis labels, line visible
117-
on top
128+
comment: Semi-transparent fill, gridlines, axis labels with units present.
129+
Gradient fill not implemented (spec says 'consider').
118130
- id: SC-04
119131
name: Data Range
120132
score: 3
121133
max: 3
122134
passed: true
123-
comment: Y-axis shows all data with 10% headroom, X-axis shows full date range
135+
comment: Y-axis from 0 to max*1.1. All data visible.
124136
- id: SC-05
125137
name: Legend Accuracy
126138
score: 2
127139
max: 2
128140
passed: true
129-
comment: No legend needed for single series plot
141+
comment: No legend needed for single series.
130142
- id: SC-06
131143
name: Title Format
132144
score: 2
133145
max: 2
134146
passed: true
135-
comment: 'Uses correct format: "area-basic · altair · pyplots.ai"'
147+
comment: area-basic · altair · pyplots.ai matches required format.
136148
data_quality:
137-
score: 18
149+
score: 19
138150
max: 20
139151
items:
140152
- id: DQ-01
141153
name: Feature Coverage
142154
score: 7
143155
max: 8
144156
passed: true
145-
comment: Shows trend AND cyclical pattern (weekday/weekend); missing extreme
146-
peaks/valleys that would show full dynamic range
157+
comment: Shows weekly patterns, growth trend, traffic spike, and noise. Good
158+
variety.
147159
- id: DQ-02
148160
name: Realistic Context
149161
score: 7
150162
max: 7
151163
passed: true
152-
comment: Website traffic is a perfect real-world scenario for area charts;
153-
weekday/weekend pattern is authentic
164+
comment: Daily website visitors is realistic and matches spec example.
154165
- id: DQ-03
155166
name: Appropriate Scale
156-
score: 4
167+
score: 5
157168
max: 5
158169
passed: true
159-
comment: Values 3,500-8,200 visitors/day are realistic; could show more variation
160-
in scale
170+
comment: 3,500-9,400 daily visitors is plausible for a mid-size website.
161171
code_quality:
162-
score: 9
172+
score: 10
163173
max: 10
164174
items:
165175
- id: CQ-01
166176
name: KISS Structure
167177
score: 3
168178
max: 3
169179
passed: true
170-
comment: 'Clean linear structure: importsdata → plot → save'
180+
comment: 'Clean flat structure: imports, data, chart, save.'
171181
- id: CQ-02
172182
name: Reproducibility
173183
score: 3
174184
max: 3
175185
passed: true
176-
comment: Uses `np.random.seed(42)`
186+
comment: np.random.seed(42) ensures deterministic output.
177187
- id: CQ-03
178188
name: Clean Imports
179189
score: 2
180190
max: 2
181191
passed: true
182-
comment: All imports (altair, numpy, pandas) are used
192+
comment: Only altair, numpy, pandas imported. All used.
183193
- id: CQ-04
184194
name: No Deprecated API
185195
score: 1
186196
max: 1
187197
passed: true
188-
comment: Modern Altair API throughout
198+
comment: Uses current Altair 6.x API.
189199
- id: CQ-05
190200
name: Output Correct
191-
score: 0
201+
score: 1
192202
max: 1
193-
passed: false
194-
comment: Saves correctly but comment mentions wrong resolution math (1600×900×3
195-
≠ 4800×2700 correctly explained)
203+
passed: true
204+
comment: Saves as plot.png.
196205
library_features:
197-
score: 3
206+
score: 4
198207
max: 5
199208
items:
200209
- id: LF-01
201-
name: Uses distinctive library features
202-
score: 3
210+
name: Distinctive Features
211+
score: 4
203212
max: 5
204213
passed: true
205-
comment: Uses Altair's declarative grammar with `.encode()`, `.properties()`,
206-
`.configure_axis()`, and `.interactive()` for HTML output. Could leverage
207-
more Altair-specific features like tooltips in the static version.
214+
comment: Good use of declarative grammar, typed encodings, tooltips with formatting,
215+
scale config, and interactive HTML export.
208216
verdict: APPROVED

0 commit comments

Comments
 (0)