Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions plots/histogram-density/implementations/matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
""" pyplots.ai
histogram-density: Density Histogram
Library: matplotlib 3.10.8 | Python 3.13.11
Quality: 93/100 | Created: 2025-12-29
"""

import matplotlib.pyplot as plt
import numpy as np


# Data: Generate realistic test score data with a normal distribution
np.random.seed(42)
test_scores = np.random.normal(loc=75, scale=12, size=500)
# Clip to realistic score range
test_scores = np.clip(test_scores, 0, 100)

# Create theoretical normal PDF for overlay (using numpy)
mu, sigma = 75, 12
x_pdf = np.linspace(30, 110, 200)
pdf = (1 / (sigma * np.sqrt(2 * np.pi))) * np.exp(-0.5 * ((x_pdf - mu) / sigma) ** 2)

# Plot
fig, ax = plt.subplots(figsize=(16, 9))

# Density histogram (density=True normalizes so area = 1)
ax.hist(
test_scores,
bins=25,
density=True,
alpha=0.7,
color="#306998",
edgecolor="white",
linewidth=1.5,
label="Observed Distribution",
)

# Overlay theoretical normal PDF
ax.plot(x_pdf, pdf, color="#FFD43B", linewidth=3, label="Normal PDF (μ=75, σ=12)")

# Labels and styling
ax.set_xlabel("Test Score (points)", fontsize=20)
ax.set_ylabel("Probability Density", fontsize=20)
ax.set_title("histogram-density · matplotlib · pyplots.ai", fontsize=24)
ax.tick_params(axis="both", labelsize=16)
ax.legend(fontsize=16, loc="upper left")
ax.grid(True, alpha=0.3, linestyle="--")

# Set axis limits for clean display
ax.set_xlim(30, 110)
ax.set_ylim(0, None)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
25 changes: 25 additions & 0 deletions plots/histogram-density/metadata/matplotlib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library: matplotlib
specification_id: histogram-density
created: '2025-12-29T22:46:41Z'
updated: '2025-12-29T22:50:25Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20584327554
issue: 0
python_version: 3.13.11
library_version: 3.10.8
preview_url: https://storage.googleapis.com/pyplots-images/plots/histogram-density/matplotlib/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/histogram-density/matplotlib/plot_thumb.png
preview_html: null
quality_score: 93
review:
strengths:
- Excellent specification compliance with density histogram and theoretical PDF
overlay
- Clean, readable code following KISS principles
- Great color contrast between histogram bars and PDF curve
- Perfect title format and axis labeling with units
- Realistic test score data scenario with appropriate sample size (n=500)
weaknesses:
- Could use more distinctive matplotlib features like fill_between for PDF shading
or axvline for mean
- Legend positioned in upper left slightly overlaps with potential data area