Skip to content

Commit 18eb737

Browse files
feat(altair): implement scatter-annotated (#2817)
## Implementation: `scatter-annotated` - altair Implements the **altair** version of `scatter-annotated`. **File:** `plots/scatter-annotated/implementations/altair.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20602453376)* --------- 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 9e479ca commit 18eb737

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
""" pyplots.ai
2+
scatter-annotated: Annotated Scatter Plot with Text Labels
3+
Library: altair 6.0.0 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import altair as alt
8+
import numpy as np
9+
import pandas as pd
10+
11+
12+
# Data - Selected tech companies showing range of revenue/profit metrics
13+
np.random.seed(42)
14+
companies = ["NVIDIA", "Apple", "Microsoft", "Amazon", "Google", "Meta", "Adobe", "Oracle", "Tesla", "Intel"]
15+
# Revenue (billions USD) - realistic values
16+
revenue = np.array([61, 385, 211, 574, 307, 135, 19, 50, 97, 63])
17+
# Profit margin (%) - realistic values
18+
profit_margin = np.array([55, 25, 35, 6, 22, 20, 34, 26, 11, 8])
19+
20+
df = pd.DataFrame({"company": companies, "revenue": revenue, "profit_margin": profit_margin})
21+
22+
# Points layer
23+
points = (
24+
alt.Chart(df)
25+
.mark_point(size=250, filled=True, opacity=0.7, color="#306998")
26+
.encode(
27+
x=alt.X("revenue:Q", title="Revenue (Billions USD)", scale=alt.Scale(domain=[0, 620])),
28+
y=alt.Y("profit_margin:Q", title="Profit Margin (%)", scale=alt.Scale(domain=[0, 60])),
29+
tooltip=["company:N", "revenue:Q", "profit_margin:Q"],
30+
)
31+
)
32+
33+
# Text labels layer
34+
labels = (
35+
alt.Chart(df)
36+
.mark_text(align="left", dx=12, dy=-8, fontSize=18, fontWeight="bold", color="#333333")
37+
.encode(x=alt.X("revenue:Q"), y=alt.Y("profit_margin:Q"), text="company:N")
38+
)
39+
40+
# Combine layers
41+
chart = (
42+
(points + labels)
43+
.properties(
44+
width=1600,
45+
height=900,
46+
title=alt.Title(text="scatter-annotated · altair · pyplots.ai", fontSize=28, anchor="middle"),
47+
)
48+
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.3)
49+
.configure_view(strokeWidth=0)
50+
)
51+
52+
# Save as PNG (4800x2700 with scale_factor=3)
53+
chart.save("plot.png", scale_factor=3.0)
54+
55+
# Save as HTML for interactivity
56+
chart.save("plot.html")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library: altair
2+
specification_id: scatter-annotated
3+
created: '2025-12-30T17:49:20Z'
4+
updated: '2025-12-30T17:59:04Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602453376
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.0.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/altair/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/altair/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/scatter-annotated/altair/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent text legibility with appropriate font sizes for high-resolution output
17+
- Clean declarative layer composition using Altair's grammar of graphics
18+
- Realistic, neutral dataset with recognizable tech companies and accurate financials
19+
- Smart label positioning with consistent dx/dy offsets to avoid point overlap
20+
- Proper use of tooltips for interactivity in HTML output
21+
weaknesses:
22+
- Missing connector lines/arrows from labels to points as mentioned in specification
23+
notes
24+
- Could leverage more Altair-specific features like conditional formatting or selections

0 commit comments

Comments
 (0)