Skip to content

Commit ef433f1

Browse files
update(density-basic): seaborn — comprehensive quality review (#4381)
## Summary Updated **seaborn** implementation for **density-basic**. **Changes:** Comprehensive quality review ### Changes - Improved visual design and spec compliance - Quality: 92/100 (local self-evaluation) ## 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 226ecd2 commit ef433f1

2 files changed

Lines changed: 181 additions & 127 deletions

File tree

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,74 @@
11
""" pyplots.ai
22
density-basic: Basic Density Plot
3-
Library: seaborn 0.13.2 | Python 3.13.11
4-
Quality: 93/100 | Created: 2025-12-23
3+
Library: seaborn 0.13.2 | Python 3.14.3
4+
Quality: 91/100 | Updated: 2026-02-23
55
"""
66

77
import matplotlib.pyplot as plt
88
import numpy as np
99
import seaborn as sns
1010

1111

12-
# Data - create a realistic bimodal distribution of test scores
12+
# Data - bimodal distribution of test scores
1313
np.random.seed(42)
1414
test_scores = np.concatenate(
1515
[
16-
np.random.normal(72, 10, 300), # Main group centered at 72
17-
np.random.normal(88, 5, 100), # High achievers group
16+
np.random.normal(68, 8, 280), # Main group centered at 68
17+
np.random.normal(90, 4, 120), # High achievers group
1818
]
1919
)
2020

21-
# Create figure
21+
# Plot
2222
fig, ax = plt.subplots(figsize=(16, 9))
2323

24-
# Plot density curve with fill
25-
sns.kdeplot(data=test_scores, ax=ax, fill=True, alpha=0.6, color="#306998", linewidth=3)
24+
# KDE line first (for peak detection), then fill
25+
sns.kdeplot(data=test_scores, ax=ax, fill=False, color="#306998", linewidth=3, bw_adjust=0.9)
26+
line = ax.get_lines()[0]
27+
x_kde, y_kde = line.get_xdata(), line.get_ydata()
28+
ax.fill_between(x_kde, y_kde, alpha=0.5, color="#306998")
2629

27-
# Add rug plot to show individual observations
28-
sns.rugplot(data=test_scores, ax=ax, color="#306998", alpha=0.3, height=0.03)
30+
sns.rugplot(data=test_scores, ax=ax, color="#1a3a5c", alpha=0.5, height=0.05)
31+
32+
# Annotate the two peaks to tell the bimodal story
33+
peak1_idx = np.argmax(y_kde[x_kde < 80])
34+
peak2_idx = len(y_kde[x_kde < 80]) + np.argmax(y_kde[x_kde >= 80])
35+
36+
px1, py1 = x_kde[peak1_idx], y_kde[peak1_idx]
37+
ax.annotate(
38+
"Main group",
39+
xy=(px1, py1),
40+
xytext=(px1 - 14, py1 - 0.008),
41+
fontsize=16,
42+
fontweight="medium",
43+
color="#1a3a5c",
44+
arrowprops={"arrowstyle": "->", "color": "#1a3a5c", "lw": 1.5},
45+
ha="center",
46+
va="top",
47+
)
48+
ax.axvline(px1, color="#306998", alpha=0.15, linestyle="--", linewidth=1.5)
49+
50+
px2, py2 = x_kde[peak2_idx], y_kde[peak2_idx]
51+
ax.annotate(
52+
"High achievers",
53+
xy=(px2, py2),
54+
xytext=(px2 + 12, py2 - 0.004),
55+
fontsize=16,
56+
fontweight="medium",
57+
color="#1a3a5c",
58+
arrowprops={"arrowstyle": "->", "color": "#1a3a5c", "lw": 1.5},
59+
ha="center",
60+
va="top",
61+
)
62+
ax.axvline(px2, color="#306998", alpha=0.15, linestyle="--", linewidth=1.5)
2963

3064
# Style
3165
ax.set_xlabel("Test Score (points)", fontsize=20)
3266
ax.set_ylabel("Density", fontsize=20)
33-
ax.set_title("density-basic · seaborn · pyplots.ai", fontsize=24)
67+
ax.set_title("density-basic \u00b7 seaborn \u00b7 pyplots.ai", fontsize=24, fontweight="medium")
3468
ax.tick_params(axis="both", labelsize=16)
35-
ax.grid(True, alpha=0.3, linestyle="--")
69+
ax.spines["top"].set_visible(False)
70+
ax.spines["right"].set_visible(False)
71+
ax.yaxis.grid(True, alpha=0.2, linewidth=0.8)
3672

3773
plt.tight_layout()
3874
plt.savefig("plot.png", dpi=300, bbox_inches="tight")

0 commit comments

Comments
 (0)