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

import numpy as np
import pandas as pd
import plotly.graph_objects as go


# Data - Daily temperature readings with noise
np.random.seed(42)

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

# Create realistic temperature pattern with seasonal trend + noise
days = np.arange(200)
seasonal = 15 * np.sin(2 * np.pi * days / 365 - np.pi / 2) # Seasonal component
trend = 0.02 * days # Slight warming trend
noise = np.random.randn(200) * 3 # Daily fluctuations
base_temp = 12 # Base temperature (Celsius)

raw_values = base_temp + seasonal + trend + noise

# Create DataFrame
df = pd.DataFrame({"date": dates, "value": raw_values})

# Calculate 14-day rolling average
window_size = 14
df["rolling_avg"] = df["value"].rolling(window=window_size, center=False).mean()

# Create figure
fig = go.Figure()

# Raw data - lighter, semi-transparent line
fig.add_trace(
go.Scatter(
x=df["date"], y=df["value"], mode="lines", name="Raw Data", line=dict(color="#306998", width=1.5), opacity=0.4
)
)

# Rolling average - prominent smooth line
fig.add_trace(
go.Scatter(
x=df["date"],
y=df["rolling_avg"],
mode="lines",
name=f"{window_size}-Day Rolling Average",
line=dict(color="#FFD43B", width=4),
)
)

# Layout for 4800x2700 canvas
fig.update_layout(
title=dict(text="line-timeseries-rolling · plotly · pyplots.ai", font=dict(size=32), x=0.5, xanchor="center"),
xaxis=dict(
title=dict(text="Date", font=dict(size=24)),
tickfont=dict(size=18),
showgrid=True,
gridwidth=1,
gridcolor="rgba(0,0,0,0.1)",
),
yaxis=dict(
title=dict(text="Temperature (°C)", font=dict(size=24)),
tickfont=dict(size=18),
showgrid=True,
gridwidth=1,
gridcolor="rgba(0,0,0,0.1)",
),
template="plotly_white",
legend=dict(
font=dict(size=20),
x=0.02,
y=0.98,
xanchor="left",
yanchor="top",
bgcolor="rgba(255,255,255,0.8)",
bordercolor="rgba(0,0,0,0.2)",
borderwidth=1,
),
margin=dict(l=100, r=50, t=100, b=80),
plot_bgcolor="white",
)

# Save as PNG (4800x2700)
fig.write_image("plot.png", width=1600, height=900, scale=3)

# Save interactive HTML
fig.write_html("plot.html", include_plotlyjs="cdn")
28 changes: 28 additions & 0 deletions plots/line-timeseries-rolling/metadata/plotly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library: plotly
specification_id: line-timeseries-rolling
created: '2025-12-30T17:47:33Z'
updated: '2025-12-30T17:51:40Z'
generated_by: claude-opus-4-5-20251101
workflow_run: 20602448540
issue: 0
python_version: 3.13.11
library_version: 6.5.0
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot_thumb.png
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-timeseries-rolling/plotly/plot.html
quality_score: 93
review:
strengths:
- Excellent visual clarity with well-chosen colors (blue raw data, yellow rolling
average) that provide strong contrast
- Rolling average line appropriately prominent (width=4) while raw data is appropriately
subdued (opacity=0.4)
- Legend includes the window size (14-Day Rolling Average) as specified in the spec
- Clean code structure following KISS principles with proper seed for reproducibility
- Realistic temperature scenario with believable seasonal patterns
- Produces both PNG and interactive HTML outputs leveraging Plotly strengths
weaknesses:
- Grid opacity at 0.1 is almost too subtle; could be increased to 0.2-0.3 for better
readability
- Could leverage more Plotly-specific features like customized hover templates showing
both raw and rolling values, or a range selector for interactivity