Skip to content

Commit 7a25b20

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

2 files changed

Lines changed: 142 additions & 135 deletions

File tree

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,66 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
scatter-basic: Basic Scatter Plot
3-
Library: plotnine 0.15.3 | Python 3.14
4-
Quality: 93/100 | Created: 2025-12-22
3+
Library: plotnine 0.15.3 | Python 3.14.4
4+
Quality: 87/100 | Created: 2026-04-23
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
911
from plotnine import (
1012
aes,
11-
annotate,
1213
element_blank,
1314
element_line,
1415
element_rect,
1516
element_text,
1617
geom_point,
1718
ggplot,
1819
labs,
19-
scale_x_continuous,
20-
scale_y_continuous,
21-
stat_smooth,
2220
theme,
2321
theme_minimal,
2422
)
2523

2624

27-
# Data: Study hours vs exam scores (realistic educational context)
25+
# Theme tokens
26+
THEME = os.getenv("ANYPLOT_THEME", "light")
27+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
28+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
29+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
30+
GRID = INK
31+
GRID_ALPHA = 0.10
32+
BRAND = "#009E73"
33+
34+
# Data
2835
np.random.seed(42)
29-
n_points = 150
36+
n_points = 180
3037
study_hours = np.random.uniform(1, 10, n_points)
31-
base_scores = 35 + study_hours * 6
38+
base_scores = 32 + study_hours * 6
3239
noise = np.random.randn(n_points) * 7
3340
exam_scores = np.clip(base_scores + noise, 15, 100)
34-
3541
df = pd.DataFrame({"study_hours": study_hours, "exam_scores": exam_scores})
3642

37-
# Compute correlation for annotation
38-
correlation = df["study_hours"].corr(df["exam_scores"])
39-
4043
# Plot
4144
plot = (
4245
ggplot(df, aes(x="study_hours", y="exam_scores"))
43-
+ geom_point(fill="#306998", color="#1a3a5c", shape="o", alpha=0.65, size=5, stroke=0.3)
44-
+ stat_smooth(method="lm", color="#e3822a", size=1.2, alpha=0.15, linetype="solid")
45-
+ annotate("text", x=2.0, y=97, label=f"r = {correlation:.2f}", size=14, color="#444444", fontstyle="italic")
46-
+ annotate("text", x=2.0, y=92, label="Strong positive correlation", size=10, color="#777777")
47-
+ scale_x_continuous(breaks=range(1, 11), limits=(0.5, 10.5))
48-
+ scale_y_continuous(breaks=range(20, 101, 10), limits=(10, 105))
49-
+ labs(
50-
x="Study Hours (per week)",
51-
y="Exam Score (points)",
52-
title="scatter-basic · plotnine · pyplots.ai",
53-
subtitle="More study time correlates with higher exam performance",
54-
)
46+
+ geom_point(color=BRAND, fill=BRAND, alpha=0.70, size=4.0, stroke=0.4)
47+
+ labs(x="Study Hours (per week)", y="Exam Score (points)", title="scatter-basic · plotnine · anyplot.ai")
5548
+ theme_minimal()
5649
+ theme(
5750
figure_size=(16, 9),
58-
text=element_text(size=14, color="#333333"),
59-
axis_title=element_text(size=20, weight="bold", color="#222222"),
60-
axis_text=element_text(size=16, color="#555555"),
61-
plot_title=element_text(size=24, weight="bold", color="#1a1a1a"),
62-
plot_subtitle=element_text(size=17, color="#666666"),
63-
panel_grid_major=element_line(color="#e0e0e0", size=0.4),
51+
text=element_text(size=14, color=INK_SOFT),
52+
plot_title=element_text(size=24, color=INK, ha="left", margin={"b": 16}),
53+
axis_title_x=element_text(size=20, color=INK, margin={"t": 12}),
54+
axis_title_y=element_text(size=20, color=INK, margin={"r": 12}),
55+
axis_text=element_text(size=16, color=INK_SOFT),
56+
axis_ticks=element_blank(),
57+
axis_line=element_line(color=INK_SOFT, size=0.6),
58+
panel_grid_major=element_line(color=GRID, size=0.4, alpha=GRID_ALPHA),
6459
panel_grid_minor=element_blank(),
65-
plot_background=element_rect(fill="white", color="white"),
66-
panel_background=element_rect(fill="#fafafa", color="white"),
60+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
61+
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
6762
)
6863
)
6964

7065
# Save
71-
plot.save("plot.png", dpi=300, verbose=False)
66+
plot.save(f"plot-{THEME}.png", dpi=300, verbose=False)

0 commit comments

Comments
 (0)