Skip to content

Commit df69288

Browse files
update(violin-basic): matplotlib — comprehensive quality review
Comprehensive quality review improving code quality, data choice, visual design, spec compliance, and library feature usage.
1 parent e9894a3 commit df69288

4 files changed

Lines changed: 50 additions & 42 deletions

File tree

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,68 @@
11
""" pyplots.ai
22
violin-basic: Basic Violin Plot
3-
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: matplotlib 3.10.8 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-21
55
"""
66

77
import matplotlib.pyplot as plt
88
import numpy as np
99

1010

11-
# Data - simulated test scores across different schools
11+
# Data - simulated test scores (0-100) across different schools
1212
np.random.seed(42)
1313
categories = ["School A", "School B", "School C", "School D"]
1414
data = [
15-
np.random.normal(75, 10, 150), # School A: centered around 75
16-
np.random.normal(82, 8, 150), # School B: higher scores, less spread
17-
np.random.normal(68, 15, 150), # School C: lower average, more spread
18-
np.random.normal(78, 12, 150), # School D: moderate
15+
np.clip(np.random.normal(75, 10, 150), 0, 100), # School A: centered around 75
16+
np.clip(np.random.normal(85, 6, 150), 0, 100), # School B: high scores, tight cluster
17+
np.clip(np.random.normal(62, 15, 150), 0, 100), # School C: lower average, wide spread
18+
np.clip(
19+
np.concatenate([np.random.normal(70, 5, 80), np.random.normal(88, 4, 70)]), 0, 100
20+
), # School D: bimodal (two subgroups)
1921
]
2022

21-
# Create plot (4800x2700 px)
23+
# Plot
2224
fig, ax = plt.subplots(figsize=(16, 9))
2325

24-
# Create violin plot with quartile markers
25-
parts = ax.violinplot(data, positions=range(len(categories)), showmeans=False, showmedians=True, showextrema=True)
26+
# Violin plot with built-in quartile lines and facecolor/linecolor params
27+
parts = ax.violinplot(
28+
data,
29+
positions=range(len(categories)),
30+
quantiles=[[0.25, 0.5, 0.75]] * len(categories),
31+
showmeans=False,
32+
showmedians=False,
33+
showextrema=False,
34+
bw_method=0.3,
35+
widths=0.75,
36+
)
2637

27-
# Style the violins with Python Blue
28-
for pc in parts["bodies"]:
29-
pc.set_facecolor("#306998")
38+
# Style violin bodies with shade intensity by median value
39+
medians = [np.median(d) for d in data]
40+
median_min, median_max = min(medians), max(medians)
41+
base_blue = np.array([0x30, 0x69, 0x98]) / 255 # Python Blue #306998
42+
43+
for i, pc in enumerate(parts["bodies"]):
44+
t = (medians[i] - median_min) / (median_max - median_min) if median_max > median_min else 0.5
45+
pc.set_facecolor(base_blue * (0.6 + 0.4 * t))
3046
pc.set_edgecolor("#1e4a6e")
31-
pc.set_alpha(0.7)
47+
pc.set_alpha(0.75)
3248
pc.set_linewidth(2)
3349

34-
# Style the lines (median, min, max)
35-
parts["cmedians"].set_color("#FFD43B")
36-
parts["cmedians"].set_linewidth(3)
37-
parts["cmins"].set_color("#1e4a6e")
38-
parts["cmins"].set_linewidth(2)
39-
parts["cmaxes"].set_color("#1e4a6e")
40-
parts["cmaxes"].set_linewidth(2)
41-
parts["cbars"].set_color("#1e4a6e")
42-
parts["cbars"].set_linewidth(2)
43-
44-
# Add quartile markers (Q1 and Q3) as box indicators
45-
quartile1 = [np.percentile(d, 25) for d in data]
46-
quartile3 = [np.percentile(d, 75) for d in data]
47-
48-
# Draw thin boxes for interquartile range
49-
for i, (q1, q3) in enumerate(zip(quartile1, quartile3, strict=True)):
50-
ax.vlines(i, q1, q3, color="#1e4a6e", linewidth=6, zorder=3)
51-
52-
# Labels and styling (scaled font sizes for 4800x2700)
50+
# Style quantile lines: white for Q1/Q3, yellow for median
51+
parts["cquantiles"].set_colors(["white", "#FFD43B", "white"] * len(categories))
52+
parts["cquantiles"].set_linewidths([2, 3.5, 2] * len(categories))
53+
54+
# Labels and styling
5355
ax.set_xticks(range(len(categories)))
5456
ax.set_xticklabels(categories)
5557
ax.set_xlabel("School", fontsize=20)
5658
ax.set_ylabel("Test Score (points)", fontsize=20)
57-
ax.set_title("violin-basic · matplotlib · pyplots.ai", fontsize=24)
59+
ax.set_title("violin-basic \u00b7 matplotlib \u00b7 pyplots.ai", fontsize=24, fontweight="medium")
5860
ax.tick_params(axis="both", labelsize=16)
59-
ax.grid(True, alpha=0.3, linestyle="--", axis="y")
61+
62+
# Spine removal and grid per library rules
63+
ax.spines["top"].set_visible(False)
64+
ax.spines["right"].set_visible(False)
65+
ax.yaxis.grid(True, alpha=0.2, linewidth=0.8)
6066

6167
plt.tight_layout()
6268
plt.savefig("plot.png", dpi=300, bbox_inches="tight")

plots/violin-basic/metadata/matplotlib.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: matplotlib
22
specification_id: violin-basic
33
created: '2025-12-23T00:35:08Z'
4-
updated: '2025-12-23T00:38:15Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-21T22:25:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20447775895
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 3.10.8
8+
python_version: '3.14.3'
9+
library_version: '3.10.8'
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/violin-basic/matplotlib/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/violin-basic/matplotlib/plot_thumb.png
1212
preview_html: null
13-
quality_score: 92
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

plots/violin-basic/specification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ A violin plot combining a box plot with a kernel density estimation on each side
1616
- `category` (string) - group labels for comparison
1717
- `value` (numeric) - numerical values to plot
1818
- Size: 30-1000 points per category, 2-6 categories
19+
- Example: Test scores (50-100) across 4 class groups with distinct distribution shapes
1920

2021
## Notes
2122

2223
- Show quartile markers inside the violin
2324
- Use mirrored density on both sides
2425
- Include median line
25-
- Consider split violins for comparing two conditions

plots/violin-basic/specification.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Basic Violin Plot
66

77
# Specification tracking
88
created: 2025-12-14T09:45:06Z
9-
updated: 2025-12-14T09:45:06Z
9+
updated: 2026-02-21T12:00:00Z
1010
issue: 722
1111
suggested: MarkusNeusinger
1212

@@ -16,6 +16,7 @@ tags:
1616
- violin
1717
data_type:
1818
- numeric
19+
- continuous
1920
- categorical
2021
domain:
2122
- statistics
@@ -24,3 +25,4 @@ tags:
2425
- basic
2526
- distribution
2627
- density
28+
- comparison

0 commit comments

Comments
 (0)