Skip to content

Commit 3a8b3b7

Browse files
feat(letsplot): implement step-basic (#5627)
## Implementation: `step-basic` - python/letsplot Implements the **python/letsplot** version of `step-basic`. **File:** `plots/step-basic/implementations/python/letsplot.py` **Parent Issue:** #956 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25166044399)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 1045771 commit 3a8b3b7

2 files changed

Lines changed: 222 additions & 151 deletions

File tree

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,84 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
step-basic: Basic Step Plot
3-
Library: letsplot 4.8.2 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: letsplot 4.9.0 | Python 3.13.13
4+
Quality: 88/100 | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
9-
from lets_plot import * # noqa: F403
10-
from lets_plot.export import ggsave as export_ggsave
11+
from lets_plot import (
12+
LetsPlot,
13+
aes,
14+
element_blank,
15+
element_line,
16+
element_rect,
17+
element_text,
18+
geom_area,
19+
geom_point,
20+
geom_step,
21+
geom_text,
22+
ggplot,
23+
ggsave,
24+
ggsize,
25+
labs,
26+
scale_x_continuous,
27+
theme,
28+
theme_minimal,
29+
)
1130

1231

13-
LetsPlot.setup_html() # noqa: F405
32+
LetsPlot.setup_html()
33+
34+
# Theme tokens
35+
THEME = os.getenv("ANYPLOT_THEME", "light")
36+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
37+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
38+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
39+
RULE = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)"
40+
BRAND = "#009E73" # Okabe-Ito position 1 — always first series
1441

1542
# Data - Monthly cumulative sales figures (in thousands)
1643
np.random.seed(42)
1744
months = np.arange(1, 13)
18-
# Monthly sales that accumulate over the year
1945
monthly_sales = np.array([45, 52, 48, 61, 55, 72, 68, 75, 82, 78, 91, 95])
2046
cumulative_sales = np.cumsum(monthly_sales)
2147

2248
df = pd.DataFrame({"month": months, "cumulative_sales": cumulative_sales})
2349

24-
# Plot - Step plot showing cumulative values that remain constant between changes
50+
# Annotation: label the year-end total near the final data point
51+
total = int(cumulative_sales[-1])
52+
label_df = pd.DataFrame({"month": [11.4], "cumulative_sales": [total + 52], "label": [f"Year-end total: ${total}K"]})
53+
54+
# Plot
2555
plot = (
26-
ggplot(df, aes(x="month", y="cumulative_sales")) # noqa: F405
27-
+ geom_step(color="#306998", size=2, direction="hv") # noqa: F405
28-
+ geom_point(color="#FFD43B", size=5, stroke=1) # noqa: F405
29-
+ labs( # noqa: F405
30-
x="Month", y="Cumulative Sales ($K)", title="step-basic · letsplot · pyplots.ai"
56+
ggplot(df, aes(x="month", y="cumulative_sales"))
57+
+ geom_area(fill=BRAND, alpha=0.15)
58+
+ geom_step(color=BRAND, size=2, direction="hv")
59+
+ geom_point(color=BRAND, size=6, alpha=0.9)
60+
+ geom_text(
61+
data=label_df, mapping=aes(x="month", y="cumulative_sales", label="label"), color=INK_SOFT, size=13, hjust=1
3162
)
32-
+ scale_x_continuous(breaks=list(range(1, 13))) # noqa: F405
33-
+ ggsize(1600, 900) # noqa: F405
34-
+ theme_minimal() # noqa: F405
35-
+ theme( # noqa: F405
36-
axis_text=element_text(size=16), # noqa: F405
37-
axis_title=element_text(size=20), # noqa: F405
38-
plot_title=element_text(size=24), # noqa: F405
39-
panel_grid=element_line(color="#CCCCCC", size=0.5, linetype="dashed"), # noqa: F405
63+
+ labs(x="Month", y="Cumulative Sales ($K)", title="step-basic · letsplot · anyplot.ai")
64+
+ scale_x_continuous(breaks=list(range(1, 13)))
65+
+ ggsize(1600, 900)
66+
+ theme_minimal()
67+
+ theme(
68+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
69+
panel_background=element_rect(fill=PAGE_BG),
70+
panel_grid_major_x=element_blank(),
71+
panel_grid_major_y=element_line(color=RULE, size=0.3),
72+
panel_grid_minor=element_blank(),
73+
axis_title=element_text(color=INK, size=20),
74+
axis_text=element_text(color=INK_SOFT, size=16),
75+
axis_line=element_line(color=INK_SOFT),
76+
plot_title=element_text(color=INK, size=24),
4077
)
4178
)
4279

4380
# Save PNG (scale 3x to get 4800 x 2700 px)
44-
export_ggsave(plot, filename="plot.png", path=".", scale=3)
81+
ggsave(plot, f"plot-{THEME}.png", path=".", scale=3)
4582

4683
# Save HTML for interactive version
47-
export_ggsave(plot, filename="plot.html", path=".")
84+
ggsave(plot, f"plot-{THEME}.html", path=".")

0 commit comments

Comments
 (0)