Skip to content

Commit b38dcf4

Browse files
feat(matplotlib): implement line-timeseries-rolling (#2805)
## Implementation: `line-timeseries-rolling` - matplotlib Implements the **matplotlib** version of `line-timeseries-rolling`. **File:** `plots/line-timeseries-rolling/implementations/matplotlib.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20602448619)* --------- 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 84e4e86 commit b38dcf4

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
""" pyplots.ai
2+
line-timeseries-rolling: Time Series with Rolling Average Overlay
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
11+
12+
# Data - Daily temperature readings with 7-day rolling average
13+
np.random.seed(42)
14+
15+
# Generate 180 days of temperature data (6 months)
16+
dates = pd.date_range("2024-01-01", periods=180, freq="D")
17+
18+
# Create seasonal temperature pattern with noise
19+
# Base seasonal pattern: winter -> spring -> summer
20+
day_of_year = np.arange(180)
21+
seasonal = 5 + 15 * np.sin(2 * np.pi * (day_of_year - 30) / 365) # Seasonal trend
22+
noise = np.random.normal(0, 3, 180) # Daily variation
23+
temperature = seasonal + noise
24+
25+
# Create DataFrame and calculate rolling average
26+
df = pd.DataFrame({"date": dates, "temperature": temperature})
27+
df["rolling_avg"] = df["temperature"].rolling(window=7, center=True).mean()
28+
29+
# Plot
30+
fig, ax = plt.subplots(figsize=(16, 9))
31+
32+
# Raw data - thin, semi-transparent line
33+
ax.plot(df["date"], df["temperature"], linewidth=1.5, alpha=0.5, color="#306998", label="Daily Temperature")
34+
35+
# Rolling average - prominent smooth line
36+
ax.plot(df["date"], df["rolling_avg"], linewidth=3.5, color="#FFD43B", label="7-Day Rolling Average")
37+
38+
# Labels and styling
39+
ax.set_xlabel("Date", fontsize=20)
40+
ax.set_ylabel("Temperature (°C)", fontsize=20)
41+
ax.set_title("line-timeseries-rolling · matplotlib · pyplots.ai", fontsize=24)
42+
ax.tick_params(axis="both", labelsize=16)
43+
ax.legend(fontsize=16, loc="upper left")
44+
ax.grid(True, alpha=0.3, linestyle="--")
45+
46+
# Format x-axis dates
47+
fig.autofmt_xdate(rotation=30)
48+
49+
plt.tight_layout()
50+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library: matplotlib
2+
specification_id: line-timeseries-rolling
3+
created: '2025-12-30T17:48:15Z'
4+
updated: '2025-12-30T17:55:37Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602448619
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/line-timeseries-rolling/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent dual-layer visualization with clear contrast between raw data and rolling
17+
average
18+
- Realistic seasonal temperature data that effectively demonstrates the rolling
19+
average smoothing effect
20+
- Proper use of alpha transparency for raw data line making the rolling average
21+
prominent
22+
- Clean KISS code structure following matplotlib best practices
23+
- Well-formatted date axis with appropriate rotation for readability
24+
weaknesses:
25+
- Raw data line could be slightly thinner (linewidth=1 instead of 1.5) for even
26+
better contrast with rolling average
27+
- Consider adding a subtle shaded region between raw and rolling average to emphasize
28+
the smoothing effect

0 commit comments

Comments
 (0)