Skip to content

Commit 869aa7d

Browse files
update(violin-basic): plotnine — comprehensive quality review (#4327)
## Summary Updated **plotnine** implementation for **violin-basic**. **Changes:** Comprehensive quality review improving code quality, data choice, visual design, spec compliance, and library feature usage. ### Changes - Improved data generation with distinct distribution shapes per category - Enhanced visual design (explicit font sizes, refined color palette, layout balance) - Fixed review weaknesses from previous evaluation - Updated metadata with current library/Python versions - Preview images uploaded to GCS staging ## 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 eecbb2c commit 869aa7d

2 files changed

Lines changed: 189 additions & 144 deletions

File tree

plots/violin-basic/implementations/plotnine.py

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,75 @@
11
""" pyplots.ai
22
violin-basic: Basic Violin Plot
3-
Library: plotnine 0.15.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: plotnine 0.15.3 | Python 3.14.3
4+
Quality: 92/100 | Updated: 2026-02-21
55
"""
66

77
import numpy as np
88
import pandas as pd
9-
from plotnine import aes, element_text, geom_violin, ggplot, labs, scale_fill_manual, theme, theme_minimal
9+
from plotnine import (
10+
aes,
11+
element_blank,
12+
element_line,
13+
element_rect,
14+
element_text,
15+
geom_violin,
16+
ggplot,
17+
labs,
18+
scale_fill_manual,
19+
theme,
20+
theme_minimal,
21+
)
1022

1123

1224
# Data
1325
np.random.seed(42)
1426

15-
categories = ["Group A", "Group B", "Group C", "Group D"]
16-
data = []
27+
records = []
28+
29+
# Biology: right-skewed (many average, few high scorers)
30+
scores_bio = np.concatenate([np.random.normal(68, 6, 150), np.random.normal(85, 3, 30)])
31+
records.extend([("Biology", s) for s in scores_bio])
32+
33+
# Statistics: bimodal (two distinct clusters)
34+
scores_stat = np.concatenate([np.random.normal(55, 5, 100), np.random.normal(82, 5, 100)])
35+
records.extend([("Statistics", s) for s in scores_stat])
1736

18-
# Generate data with different distributions for each category
19-
distributions = {
20-
"Group A": (50, 10), # mean, std
21-
"Group B": (65, 15),
22-
"Group C": (45, 8),
23-
"Group D": (70, 12),
24-
}
37+
# Chemistry: tight normal (consistent performance)
38+
scores_chem = np.random.normal(74, 4, 200)
39+
records.extend([("Chemistry", s) for s in scores_chem])
2540

26-
for category, (mean, std) in distributions.items():
27-
n_points = 200
28-
values = np.random.normal(mean, std, n_points)
29-
data.extend([(category, v) for v in values])
41+
# Psychology: wide spread (high variance)
42+
scores_psych = np.random.normal(70, 14, 200)
43+
records.extend([("Psychology", s) for s in scores_psych])
44+
45+
df = pd.DataFrame(records, columns=["course", "score"])
46+
df["score"] = df["score"].clip(0, 100)
47+
df["course"] = pd.Categorical(
48+
df["course"], categories=["Biology", "Statistics", "Chemistry", "Psychology"], ordered=True
49+
)
3050

31-
df = pd.DataFrame(data, columns=["category", "value"])
51+
# Custom palette: Python Blue for focal bimodal distribution, muted tones for context
52+
palette = {"Biology": "#7BAE7F", "Statistics": "#306998", "Chemistry": "#E8A87C", "Psychology": "#B8B3D6"}
3253

3354
# Plot
3455
plot = (
35-
ggplot(df, aes(x="category", y="value", fill="category"))
36-
+ geom_violin(draw_quantiles=[0.25, 0.5, 0.75], size=1)
37-
+ scale_fill_manual(values=["#306998", "#FFD43B", "#4B8BBE", "#FFE873"])
38-
+ labs(x="Category", y="Value", title="violin-basic · plotnine · pyplots.ai")
56+
ggplot(df, aes(x="course", y="score", fill="course"))
57+
+ geom_violin(draw_quantiles=[0.25, 0.5, 0.75], alpha=0.82, color="#666666", size=0.35, trim=False)
58+
+ scale_fill_manual(values=palette)
59+
+ labs(x="Course", y="Final Exam Score (pts)", title="violin-basic \u00b7 plotnine \u00b7 pyplots.ai")
3960
+ theme_minimal()
4061
+ theme(
4162
figure_size=(16, 9),
42-
text=element_text(size=14),
43-
axis_title=element_text(size=20),
44-
axis_text=element_text(size=16),
45-
plot_title=element_text(size=24),
63+
text=element_text(size=14, color="#333333"),
64+
axis_title=element_text(size=20, color="#333333"),
65+
axis_text=element_text(size=16, color="#444444"),
66+
plot_title=element_text(size=24, color="#222222", weight="bold"),
4667
legend_position="none",
68+
panel_grid_major_x=element_blank(),
69+
panel_grid_minor=element_blank(),
70+
panel_grid_major_y=element_line(color="#dedede", size=0.3),
71+
plot_background=element_rect(fill="#fafafa", color="none"),
72+
panel_background=element_rect(fill="#fafafa", color="none"),
4773
)
4874
)
4975

0 commit comments

Comments
 (0)