Skip to content

Commit 117ec5b

Browse files
feat(plotnine): implement scatter-categorical (#2602)
## Implementation: `scatter-categorical` - plotnine Implements the **plotnine** version of `scatter-categorical`. **File:** `plots/scatter-categorical/implementations/plotnine.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594556837)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5c05395 commit 117ec5b

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
""" pyplots.ai
2+
scatter-categorical: Categorical Scatter Plot
3+
Library: plotnine 0.15.2 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
from plotnine import aes, element_text, geom_point, ggplot, labs, scale_color_manual, theme, theme_minimal
10+
11+
12+
# Data
13+
np.random.seed(42)
14+
15+
# Create sample data with 3 categories showing different patterns
16+
n_per_group = 40
17+
18+
# Group A: positive correlation
19+
x_a = np.random.normal(25, 8, n_per_group)
20+
y_a = x_a * 0.8 + np.random.normal(10, 4, n_per_group)
21+
22+
# Group B: higher values, positive correlation
23+
x_b = np.random.normal(45, 10, n_per_group)
24+
y_b = x_b * 0.6 + np.random.normal(15, 5, n_per_group)
25+
26+
# Group C: lower values, weaker correlation
27+
x_c = np.random.normal(35, 12, n_per_group)
28+
y_c = np.random.normal(35, 8, n_per_group)
29+
30+
df = pd.DataFrame(
31+
{
32+
"Temperature (°C)": np.concatenate([x_a, x_b, x_c]),
33+
"Growth Rate (cm/week)": np.concatenate([y_a, y_b, y_c]),
34+
"Plant Species": (["Species A"] * n_per_group + ["Species B"] * n_per_group + ["Species C"] * n_per_group),
35+
}
36+
)
37+
38+
# Plot
39+
plot = (
40+
ggplot(df, aes(x="Temperature (°C)", y="Growth Rate (cm/week)", color="Plant Species"))
41+
+ geom_point(size=4, alpha=0.7)
42+
+ scale_color_manual(values=["#306998", "#FFD43B", "#4ECDC4"])
43+
+ labs(
44+
x="Temperature (°C)",
45+
y="Growth Rate (cm/week)",
46+
title="scatter-categorical · plotnine · pyplots.ai",
47+
color="Plant Species",
48+
)
49+
+ theme_minimal()
50+
+ theme(
51+
figure_size=(16, 9),
52+
text=element_text(size=14),
53+
axis_title=element_text(size=20),
54+
axis_text=element_text(size=16),
55+
plot_title=element_text(size=24),
56+
legend_text=element_text(size=16),
57+
legend_title=element_text(size=18),
58+
)
59+
)
60+
61+
# Save
62+
plot.save("plot.png", dpi=300, verbose=False)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: plotnine
2+
specification_id: scatter-categorical
3+
created: '2025-12-30T10:37:18Z'
4+
updated: '2025-12-30T10:41:59Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594556837
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.15.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotnine/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/scatter-categorical/plotnine/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent text sizing with all labels clearly readable at target resolution
17+
- Clean ggplot2-style grammar of graphics implementation with proper layer composition
18+
- Smart use of three distinct data patterns (correlation, high values, scattered)
19+
demonstrating categorical differences
20+
- Colorblind-safe palette choice with good contrast between categories
21+
- Realistic biological scenario (plant species growth vs temperature)
22+
weaknesses:
23+
- Could leverage more plotnine-specific features like facet_wrap for small multiples
24+
or stat_smooth for trend lines
25+
- Legend title font size could be slightly larger for consistency with axis titles

0 commit comments

Comments
 (0)