Skip to content

Commit 763edde

Browse files
feat(matplotlib): implement histogram-density (#2451)
## Implementation: `histogram-density` - matplotlib Implements the **matplotlib** version of `histogram-density`. **File:** `plots/histogram-density/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20584327554)* --------- 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 df51292 commit 763edde

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" pyplots.ai
2+
histogram-density: Density Histogram
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-29
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
# Data: Generate realistic test score data with a normal distribution
12+
np.random.seed(42)
13+
test_scores = np.random.normal(loc=75, scale=12, size=500)
14+
# Clip to realistic score range
15+
test_scores = np.clip(test_scores, 0, 100)
16+
17+
# Create theoretical normal PDF for overlay (using numpy)
18+
mu, sigma = 75, 12
19+
x_pdf = np.linspace(30, 110, 200)
20+
pdf = (1 / (sigma * np.sqrt(2 * np.pi))) * np.exp(-0.5 * ((x_pdf - mu) / sigma) ** 2)
21+
22+
# Plot
23+
fig, ax = plt.subplots(figsize=(16, 9))
24+
25+
# Density histogram (density=True normalizes so area = 1)
26+
ax.hist(
27+
test_scores,
28+
bins=25,
29+
density=True,
30+
alpha=0.7,
31+
color="#306998",
32+
edgecolor="white",
33+
linewidth=1.5,
34+
label="Observed Distribution",
35+
)
36+
37+
# Overlay theoretical normal PDF
38+
ax.plot(x_pdf, pdf, color="#FFD43B", linewidth=3, label="Normal PDF (μ=75, σ=12)")
39+
40+
# Labels and styling
41+
ax.set_xlabel("Test Score (points)", fontsize=20)
42+
ax.set_ylabel("Probability Density", fontsize=20)
43+
ax.set_title("histogram-density · matplotlib · pyplots.ai", fontsize=24)
44+
ax.tick_params(axis="both", labelsize=16)
45+
ax.legend(fontsize=16, loc="upper left")
46+
ax.grid(True, alpha=0.3, linestyle="--")
47+
48+
# Set axis limits for clean display
49+
ax.set_xlim(30, 110)
50+
ax.set_ylim(0, None)
51+
52+
plt.tight_layout()
53+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: matplotlib
2+
specification_id: histogram-density
3+
created: '2025-12-29T22:46:41Z'
4+
updated: '2025-12-29T22:50:25Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20584327554
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/histogram-density/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/histogram-density/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent specification compliance with density histogram and theoretical PDF
17+
overlay
18+
- Clean, readable code following KISS principles
19+
- Great color contrast between histogram bars and PDF curve
20+
- Perfect title format and axis labeling with units
21+
- Realistic test score data scenario with appropriate sample size (n=500)
22+
weaknesses:
23+
- Could use more distinctive matplotlib features like fill_between for PDF shading
24+
or axvline for mean
25+
- Legend positioned in upper left slightly overlaps with potential data area

0 commit comments

Comments
 (0)