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
70 changes: 41 additions & 29 deletions plots/stem-basic/implementations/python/plotly.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,94 @@
""" pyplots.ai
""" anyplot.ai
stem-basic: Basic Stem Plot
Library: plotly 6.5.0 | Python 3.13.11
Quality: 93/100 | Created: 2025-12-23
Library: plotly 6.7.0 | Python 3.13.13
Quality: 90/100 | Updated: 2026-04-30
"""

import os

import numpy as np
import plotly.graph_objects as go


# Theme tokens
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
GRID = "rgba(26,26,23,0.20)" if THEME == "light" else "rgba(240,239,232,0.20)"
BRAND = "#009E73" # Okabe-Ito position 1

# Data - Discrete signal samples (damped oscillation)
np.random.seed(42)
x = np.arange(0, 30)
y = np.exp(-x / 10) * np.cos(x * 0.8) + np.random.randn(30) * 0.05

# Create figure
# Plot
fig = go.Figure()

# Add baseline at y=0
# Baseline at y=0
fig.add_trace(
go.Scatter(
x=[x.min() - 0.5, x.max() + 0.5],
y=[0, 0],
mode="lines",
line={"color": "#333333", "width": 2},
line={"color": INK_SOFT, "width": 2},
showlegend=False,
hoverinfo="skip",
)
)

# Add stems (vertical lines from baseline to data points)
# Stems (vertical lines from baseline to data points)
for xi, yi in zip(x, y, strict=True):
fig.add_trace(
go.Scatter(
x=[xi, xi],
y=[0, yi],
mode="lines",
line={"color": "#306998", "width": 2},
showlegend=False,
hoverinfo="skip",
x=[xi, xi], y=[0, yi], mode="lines", line={"color": BRAND, "width": 2}, showlegend=False, hoverinfo="skip"
)
)

# Add markers at the top of each stem
# Markers at the top of each stem
fig.add_trace(
go.Scatter(
x=x,
y=y,
mode="markers",
marker={"color": "#306998", "size": 16, "line": {"color": "white", "width": 2}},
marker={"color": BRAND, "size": 16, "line": {"color": PAGE_BG, "width": 2}},
showlegend=False,
hovertemplate="Sample: %{x}<br>Amplitude: %{y:.3f}<extra></extra>",
)
)

# Update layout for 4800x2700 px
# Style
fig.update_layout(
title={"text": "stem-basic · plotly · pyplots.ai", "font": {"size": 42}, "x": 0.5, "xanchor": "center"},
paper_bgcolor=PAGE_BG,
plot_bgcolor=PAGE_BG,
font={"color": INK},
title={
"text": "stem-basic · plotly · anyplot.ai",
"font": {"size": 42, "color": INK},
"x": 0.5,
"xanchor": "center",
},
xaxis={
"title": {"text": "Sample Index", "font": {"size": 36}},
"tickfont": {"size": 28},
"gridcolor": "rgba(0,0,0,0.1)",
"title": {"text": "Sample Index (n)", "font": {"size": 36, "color": INK}},
"tickfont": {"size": 28, "color": INK_SOFT},
"gridcolor": GRID,
"gridwidth": 1,
"zeroline": False,
"linecolor": INK_SOFT,
},
yaxis={
"title": {"text": "Amplitude", "font": {"size": 36}},
"tickfont": {"size": 28},
"gridcolor": "rgba(0,0,0,0.1)",
"title": {"text": "Amplitude (a.u.)", "font": {"size": 36, "color": INK}},
"tickfont": {"size": 28, "color": INK_SOFT},
"gridcolor": GRID,
"gridwidth": 1,
"zeroline": False,
"linecolor": INK_SOFT,
},
template="plotly_white",
margin={"l": 120, "r": 60, "t": 130, "b": 110},
showlegend=False,
)

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

# Save interactive HTML
fig.write_html("plot.html")
# Save
fig.write_image(f"plot-{THEME}.png", width=1600, height=900, scale=3)
fig.write_html(f"plot-{THEME}.html", include_plotlyjs="cdn")
Loading
Loading