Skip to content

Commit dc1b07a

Browse files
feat(plotly): implement line-timeseries (#6117)
## Implementation: `line-timeseries` - python/plotly Implements the **python/plotly** version of `line-timeseries`. **File:** `plots/line-timeseries/implementations/python/plotly.py` **Parent Issue:** #2006 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25590297718)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 69b1f1c commit dc1b07a

2 files changed

Lines changed: 197 additions & 151 deletions

File tree

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,87 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-timeseries: Time Series Line Plot
3-
Library: plotly 6.5.0 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-26
3+
Library: plotly 6.7.0 | Python 3.13.13
4+
Quality: 90/100 | Updated: 2026-05-09
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
911
import plotly.graph_objects as go
1012

1113

12-
# Data - Daily temperature readings over one year
14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
GRID = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"
21+
BRAND = "#009E73" # Okabe-Ito position 1
22+
23+
# Data - Stock prices with uptrend
1324
np.random.seed(42)
1425
dates = pd.date_range(start="2024-01-01", end="2024-12-31", freq="D")
26+
days = np.arange(len(dates))
27+
trend = 100 + 0.15 * days
28+
volatility = 5 * np.sin(2 * np.pi * days / 60)
29+
noise = np.random.randn(len(dates)) * 2
30+
prices = trend + volatility + noise
1531

16-
# Create realistic temperature pattern with seasonal variation
17-
day_of_year = np.arange(len(dates))
18-
seasonal = 15 * np.sin(2 * np.pi * (day_of_year - 80) / 365) # Peak around late July
19-
baseline = 12 # Average temperature
20-
noise = np.random.randn(len(dates)) * 3
21-
temperatures = baseline + seasonal + noise
22-
23-
df = pd.DataFrame({"date": dates, "temperature": temperatures})
32+
df = pd.DataFrame({"date": dates, "price": prices})
2433

2534
# Create plot
2635
fig = go.Figure()
2736

2837
fig.add_trace(
2938
go.Scatter(
3039
x=df["date"],
31-
y=df["temperature"],
40+
y=df["price"],
3241
mode="lines",
33-
line={"color": "#306998", "width": 2.5},
34-
name="Temperature",
35-
hovertemplate="Date: %{x|%b %d, %Y}<br>Temperature: %{y:.1f}°C<extra></extra>",
42+
line={"color": BRAND, "width": 3},
43+
name="Stock Price",
44+
hovertemplate="Date: %{x|%b %d, %Y}<br>Price: $%{y:.2f}<extra></extra>",
3645
)
3746
)
3847

3948
# Layout for 4800x2700 px
4049
fig.update_layout(
4150
title={
42-
"text": "Daily Temperature 2024 · line-timeseries · plotly · pyplots.ai",
43-
"font": {"size": 32},
51+
"text": "line-timeseries · plotly · anyplot.ai",
52+
"font": {"size": 28, "color": INK},
4453
"x": 0.5,
4554
"xanchor": "center",
4655
},
4756
xaxis={
48-
"title": {"text": "Date", "font": {"size": 24}},
49-
"tickfont": {"size": 18},
57+
"title": {"text": "Date", "font": {"size": 22, "color": INK}},
58+
"tickfont": {"size": 18, "color": INK_SOFT},
5059
"tickformat": "%b %Y",
5160
"dtick": "M1",
52-
"gridcolor": "rgba(128, 128, 128, 0.3)",
61+
"gridcolor": GRID,
5362
"gridwidth": 1,
5463
"showgrid": True,
64+
"linecolor": INK_SOFT,
65+
"zerolinecolor": INK_SOFT,
66+
"rangeslider": {"visible": True, "thickness": 0.05},
5567
},
5668
yaxis={
57-
"title": {"text": "Temperature (°C)", "font": {"size": 24}},
58-
"tickfont": {"size": 18},
59-
"gridcolor": "rgba(128, 128, 128, 0.3)",
69+
"title": {"text": "Stock Price ($)", "font": {"size": 22, "color": INK}},
70+
"tickfont": {"size": 18, "color": INK_SOFT},
71+
"gridcolor": GRID,
6072
"gridwidth": 1,
6173
"showgrid": True,
74+
"linecolor": INK_SOFT,
75+
"zerolinecolor": INK_SOFT,
6276
},
63-
template="plotly_white",
64-
plot_bgcolor="white",
65-
paper_bgcolor="white",
77+
paper_bgcolor=PAGE_BG,
78+
plot_bgcolor=PAGE_BG,
79+
font={"color": INK},
6680
margin={"l": 100, "r": 80, "t": 120, "b": 100},
6781
showlegend=False,
82+
hovermode="x unified",
6883
)
6984

7085
# Save as PNG (4800x2700 px) and HTML
71-
fig.write_image("plot.png", width=1600, height=900, scale=3)
72-
fig.write_html("plot.html", include_plotlyjs="cdn")
86+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
87+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")

0 commit comments

Comments
 (0)