Skip to content

Commit 8184005

Browse files
feat(altair): implement scatter-basic (#5322)
## Implementation: `scatter-basic` - python/altair Implements the **python/altair** version of `scatter-basic`. **File:** `plots/scatter-basic/implementations/python/altair.py` **Parent Issue:** #611 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/24860303745)* --------- 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 cb70bd5 commit 8184005

2 files changed

Lines changed: 122 additions & 81 deletions

File tree

plots/scatter-basic/implementations/python/altair.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" anyplot.ai
22
scatter-basic: Basic Scatter Plot
33
Library: altair 6.1.0 | Python 3.14.4
4-
Quality: 88/100 | Created: 2026-04-23
4+
Quality: 89/100 | Updated: 2026-04-23
55
"""
66

77
import importlib
@@ -21,23 +21,41 @@
2121
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
2222
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
2323
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
24-
BRAND = "#009E73"
24+
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"
25+
BRAND = "#009E73" # Okabe-Ito position 1
2526

26-
# Data
27+
# Data — study hours vs. exam scores (r ~ 0.75)
2728
np.random.seed(42)
2829
n = 180
2930
study_hours = np.random.uniform(1, 12, n)
30-
exam_scores = np.clip(40 + study_hours * 4.8 + np.random.randn(n) * 7.5, 30, 100)
31+
exam_scores = np.clip(38 + study_hours * 4.8 + np.random.normal(0, 7.0, n), 30, 100)
3132
df = pd.DataFrame({"hours": study_hours, "score": exam_scores})
3233

34+
pearson_r = float(np.corrcoef(df["hours"], df["score"])[0, 1])
35+
3336
# Plot
3437
points = (
3538
alt.Chart(df)
36-
.mark_circle(size=180, opacity=0.7, color=BRAND, stroke=PAGE_BG, strokeWidth=0.8)
39+
.mark_circle(size=170, opacity=0.7, color=BRAND, stroke=PAGE_BG, strokeWidth=0.8)
3740
.encode(
38-
x=alt.X("hours:Q", title="Study Hours per Week", scale=alt.Scale(domain=[0, 13], nice=False)),
39-
y=alt.Y("score:Q", title="Exam Score (%)", scale=alt.Scale(domain=[25, 105], nice=False)),
41+
x=alt.X(
42+
"hours:Q",
43+
title="Study Hours per Week",
44+
scale=alt.Scale(domain=[0, 13], nice=False),
45+
axis=alt.Axis(tickCount=6, ticks=False, labelPadding=10, titlePadding=18),
46+
),
47+
y=alt.Y(
48+
"score:Q",
49+
title="Exam Score (%)",
50+
scale=alt.Scale(domain=[25, 105], nice=False),
51+
axis=alt.Axis(tickCount=8, ticks=False, labelPadding=10, titlePadding=18),
52+
),
53+
tooltip=[
54+
alt.Tooltip("hours:Q", title="Study hrs / wk", format=".1f"),
55+
alt.Tooltip("score:Q", title="Exam %", format=".1f"),
56+
],
4057
)
58+
.interactive()
4159
)
4260

4361
chart = (
@@ -47,19 +65,24 @@
4765
background=PAGE_BG,
4866
title=alt.Title(
4967
"scatter-basic · altair · anyplot.ai",
68+
subtitle=f"n = {n} · Pearson r = {pearson_r:.2f}",
5069
fontSize=28,
5170
fontWeight="normal",
5271
color=INK,
72+
subtitleFontSize=16,
73+
subtitleColor=INK_MUTED,
74+
subtitlePadding=6,
5375
anchor="start",
54-
offset=16,
76+
offset=20,
5577
),
5678
)
5779
.configure_view(fill=PAGE_BG, stroke=None)
5880
.configure_axis(
5981
labelFontSize=18,
6082
titleFontSize=22,
61-
titlePadding=14,
83+
titleFontWeight="normal",
6284
domainColor=INK_SOFT,
85+
domainWidth=0.9,
6386
tickColor=INK_SOFT,
6487
gridColor=INK,
6588
gridOpacity=0.10,

0 commit comments

Comments
 (0)