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
50 changes: 50 additions & 0 deletions plots/line-timeseries-rolling/implementations/matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
""" pyplots.ai
line-timeseries-rolling: Time Series with Rolling Average Overlay
Library: matplotlib 3.10.8 | Python 3.13.11
Quality: 92/100 | Created: 2025-12-30
"""

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


# Data - Daily temperature readings with 7-day rolling average
np.random.seed(42)

# Generate 180 days of temperature data (6 months)
dates = pd.date_range("2024-01-01", periods=180, freq="D")

# Create seasonal temperature pattern with noise
# Base seasonal pattern: winter -> spring -> summer
day_of_year = np.arange(180)
seasonal = 5 + 15 * np.sin(2 * np.pi * (day_of_year - 30) / 365) # Seasonal trend
noise = np.random.normal(0, 3, 180) # Daily variation
temperature = seasonal + noise

# Create DataFrame and calculate rolling average
df = pd.DataFrame({"date": dates, "temperature": temperature})
df["rolling_avg"] = df["temperature"].rolling(window=7, center=True).mean()

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

# Raw data - thin, semi-transparent line
ax.plot(df["date"], df["temperature"], linewidth=1.5, alpha=0.5, color="#306998", label="Daily Temperature")

# Rolling average - prominent smooth line
ax.plot(df["date"], df["rolling_avg"], linewidth=3.5, color="#FFD43B", label="7-Day Rolling Average")

# Labels and styling
ax.set_xlabel("Date", fontsize=20)
ax.set_ylabel("Temperature (°C)", fontsize=20)
ax.set_title("line-timeseries-rolling · 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="--")

# Format x-axis dates
fig.autofmt_xdate(rotation=30)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
28 changes: 28 additions & 0 deletions plots/line-timeseries-rolling/metadata/matplotlib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library: matplotlib
specification_id: line-timeseries-rolling
created: '2025-12-30T17:48:15Z'
updated: '2025-12-30T17:55:37Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20602448619
issue: 0
python_version: 3.13.11
library_version: 3.10.8
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/matplotlib/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/matplotlib/plot_thumb.png
preview_html: null
quality_score: 92
review:
strengths:
- Excellent dual-layer visualization with clear contrast between raw data and rolling
average
- Realistic seasonal temperature data that effectively demonstrates the rolling
average smoothing effect
- Proper use of alpha transparency for raw data line making the rolling average
prominent
- Clean KISS code structure following matplotlib best practices
- Well-formatted date axis with appropriate rotation for readability
weaknesses:
- Raw data line could be slightly thinner (linewidth=1 instead of 1.5) for even
better contrast with rolling average
- Consider adding a subtle shaded region between raw and rolling average to emphasize
the smoothing effect