Skip to content

Commit 76b2032

Browse files
feat(plotly): implement stem-basic (#5630)
## Implementation: `stem-basic` - python/plotly Implements the **python/plotly** version of `stem-basic`. **File:** `plots/stem-basic/implementations/python/plotly.py` **Parent Issue:** #972 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25171946708)* --------- 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 bfa332f commit 76b2032

2 files changed

Lines changed: 207 additions & 147 deletions

File tree

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,94 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
stem-basic: Basic Stem Plot
3-
Library: plotly 6.5.0 | Python 3.13.11
4-
Quality: 93/100 | Created: 2025-12-23
3+
Library: plotly 6.7.0 | Python 3.13.13
4+
Quality: 90/100 | Updated: 2026-04-30
55
"""
66

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

1012

13+
# Theme tokens
14+
THEME = os.getenv("ANYPLOT_THEME", "light")
15+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
16+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
17+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
18+
GRID = "rgba(26,26,23,0.20)" if THEME == "light" else "rgba(240,239,232,0.20)"
19+
BRAND = "#009E73" # Okabe-Ito position 1
20+
1121
# Data - Discrete signal samples (damped oscillation)
1222
np.random.seed(42)
1323
x = np.arange(0, 30)
1424
y = np.exp(-x / 10) * np.cos(x * 0.8) + np.random.randn(30) * 0.05
1525

16-
# Create figure
26+
# Plot
1727
fig = go.Figure()
1828

19-
# Add baseline at y=0
29+
# Baseline at y=0
2030
fig.add_trace(
2131
go.Scatter(
2232
x=[x.min() - 0.5, x.max() + 0.5],
2333
y=[0, 0],
2434
mode="lines",
25-
line={"color": "#333333", "width": 2},
35+
line={"color": INK_SOFT, "width": 2},
2636
showlegend=False,
2737
hoverinfo="skip",
2838
)
2939
)
3040

31-
# Add stems (vertical lines from baseline to data points)
41+
# Stems (vertical lines from baseline to data points)
3242
for xi, yi in zip(x, y, strict=True):
3343
fig.add_trace(
3444
go.Scatter(
35-
x=[xi, xi],
36-
y=[0, yi],
37-
mode="lines",
38-
line={"color": "#306998", "width": 2},
39-
showlegend=False,
40-
hoverinfo="skip",
45+
x=[xi, xi], y=[0, yi], mode="lines", line={"color": BRAND, "width": 2}, showlegend=False, hoverinfo="skip"
4146
)
4247
)
4348

44-
# Add markers at the top of each stem
49+
# Markers at the top of each stem
4550
fig.add_trace(
4651
go.Scatter(
4752
x=x,
4853
y=y,
4954
mode="markers",
50-
marker={"color": "#306998", "size": 16, "line": {"color": "white", "width": 2}},
55+
marker={"color": BRAND, "size": 16, "line": {"color": PAGE_BG, "width": 2}},
5156
showlegend=False,
5257
hovertemplate="Sample: %{x}<br>Amplitude: %{y:.3f}<extra></extra>",
5358
)
5459
)
5560

56-
# Update layout for 4800x2700 px
61+
# Style
5762
fig.update_layout(
58-
title={"text": "stem-basic · plotly · pyplots.ai", "font": {"size": 42}, "x": 0.5, "xanchor": "center"},
63+
paper_bgcolor=PAGE_BG,
64+
plot_bgcolor=PAGE_BG,
65+
font={"color": INK},
66+
title={
67+
"text": "stem-basic · plotly · anyplot.ai",
68+
"font": {"size": 42, "color": INK},
69+
"x": 0.5,
70+
"xanchor": "center",
71+
},
5972
xaxis={
60-
"title": {"text": "Sample Index", "font": {"size": 36}},
61-
"tickfont": {"size": 28},
62-
"gridcolor": "rgba(0,0,0,0.1)",
73+
"title": {"text": "Sample Index (n)", "font": {"size": 36, "color": INK}},
74+
"tickfont": {"size": 28, "color": INK_SOFT},
75+
"gridcolor": GRID,
6376
"gridwidth": 1,
6477
"zeroline": False,
78+
"linecolor": INK_SOFT,
6579
},
6680
yaxis={
67-
"title": {"text": "Amplitude", "font": {"size": 36}},
68-
"tickfont": {"size": 28},
69-
"gridcolor": "rgba(0,0,0,0.1)",
81+
"title": {"text": "Amplitude (a.u.)", "font": {"size": 36, "color": INK}},
82+
"tickfont": {"size": 28, "color": INK_SOFT},
83+
"gridcolor": GRID,
7084
"gridwidth": 1,
7185
"zeroline": False,
86+
"linecolor": INK_SOFT,
7287
},
73-
template="plotly_white",
7488
margin={"l": 120, "r": 60, "t": 130, "b": 110},
7589
showlegend=False,
7690
)
7791

78-
# Save as PNG (4800x2700 px)
79-
fig.write_image("plot.png", width=1600, height=900, scale=3)
80-
81-
# Save interactive HTML
82-
fig.write_html("plot.html")
92+
# Save
93+
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
94+
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")

0 commit comments

Comments
 (0)