Skip to content

Commit adbb9de

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

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
""" pyplots.ai
2+
line-timeseries-rolling: Time Series with Rolling Average Overlay
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import pandas as pd
9+
import plotly.graph_objects as go
10+
11+
12+
# Data - Daily temperature readings with noise
13+
np.random.seed(42)
14+
15+
# Generate 200 days of data
16+
dates = pd.date_range("2024-01-01", periods=200, freq="D")
17+
18+
# Create realistic temperature pattern with seasonal trend + noise
19+
days = np.arange(200)
20+
seasonal = 15 * np.sin(2 * np.pi * days / 365 - np.pi / 2) # Seasonal component
21+
trend = 0.02 * days # Slight warming trend
22+
noise = np.random.randn(200) * 3 # Daily fluctuations
23+
base_temp = 12 # Base temperature (Celsius)
24+
25+
raw_values = base_temp + seasonal + trend + noise
26+
27+
# Create DataFrame
28+
df = pd.DataFrame({"date": dates, "value": raw_values})
29+
30+
# Calculate 14-day rolling average
31+
window_size = 14
32+
df["rolling_avg"] = df["value"].rolling(window=window_size, center=False).mean()
33+
34+
# Create figure
35+
fig = go.Figure()
36+
37+
# Raw data - lighter, semi-transparent line
38+
fig.add_trace(
39+
go.Scatter(
40+
x=df["date"], y=df["value"], mode="lines", name="Raw Data", line=dict(color="#306998", width=1.5), opacity=0.4
41+
)
42+
)
43+
44+
# Rolling average - prominent smooth line
45+
fig.add_trace(
46+
go.Scatter(
47+
x=df["date"],
48+
y=df["rolling_avg"],
49+
mode="lines",
50+
name=f"{window_size}-Day Rolling Average",
51+
line=dict(color="#FFD43B", width=4),
52+
)
53+
)
54+
55+
# Layout for 4800x2700 canvas
56+
fig.update_layout(
57+
title=dict(text="line-timeseries-rolling · plotly · pyplots.ai", font=dict(size=32), x=0.5, xanchor="center"),
58+
xaxis=dict(
59+
title=dict(text="Date", font=dict(size=24)),
60+
tickfont=dict(size=18),
61+
showgrid=True,
62+
gridwidth=1,
63+
gridcolor="rgba(0,0,0,0.1)",
64+
),
65+
yaxis=dict(
66+
title=dict(text="Temperature (°C)", font=dict(size=24)),
67+
tickfont=dict(size=18),
68+
showgrid=True,
69+
gridwidth=1,
70+
gridcolor="rgba(0,0,0,0.1)",
71+
),
72+
template="plotly_white",
73+
legend=dict(
74+
font=dict(size=20),
75+
x=0.02,
76+
y=0.98,
77+
xanchor="left",
78+
yanchor="top",
79+
bgcolor="rgba(255,255,255,0.8)",
80+
bordercolor="rgba(0,0,0,0.2)",
81+
borderwidth=1,
82+
),
83+
margin=dict(l=100, r=50, t=100, b=80),
84+
plot_bgcolor="white",
85+
)
86+
87+
# Save as PNG (4800x2700)
88+
fig.write_image("plot.png", width=1600, height=900, scale=3)
89+
90+
# Save interactive HTML
91+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library: plotly
2+
specification_id: line-timeseries-rolling
3+
created: '2025-12-30T17:47:33Z'
4+
updated: '2025-12-30T17:51:40Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20602448540
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.5.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot.html
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent visual clarity with well-chosen colors (blue raw data, yellow rolling
17+
average) that provide strong contrast
18+
- Rolling average line appropriately prominent (width=4) while raw data is appropriately
19+
subdued (opacity=0.4)
20+
- Legend includes the window size (14-Day Rolling Average) as specified in the spec
21+
- Clean code structure following KISS principles with proper seed for reproducibility
22+
- Realistic temperature scenario with believable seasonal patterns
23+
- Produces both PNG and interactive HTML outputs leveraging Plotly strengths
24+
weaknesses:
25+
- Grid opacity at 0.1 is almost too subtle; could be increased to 0.2-0.3 for better
26+
readability
27+
- Could leverage more Plotly-specific features like customized hover templates showing
28+
both raw and rolling values, or a range selector for interactivity

0 commit comments

Comments
 (0)