Skip to content

Commit 94888bd

Browse files
feat(letsplot): implement andrews-curves (#6825)
## Implementation: `andrews-curves` - python/letsplot Implements the **python/letsplot** version of `andrews-curves`. **File:** `plots/andrews-curves/implementations/python/letsplot.py` **Parent Issue:** #2859 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25919380707)* --------- 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 9e60298 commit 94888bd

2 files changed

Lines changed: 190 additions & 142 deletions

File tree

plots/andrews-curves/implementations/python/letsplot.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
andrews-curves: Andrews Curves for Multivariate Data
3-
Library: letsplot 4.8.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-31
3+
Library: letsplot 4.9.0 | Python 3.13.13
4+
Quality: 91/100 | Updated: 2026-05-15
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
911
from lets_plot import (
1012
LetsPlot,
1113
aes,
14+
element_line,
15+
element_rect,
1216
element_text,
1317
geom_line,
1418
ggplot,
@@ -26,6 +30,20 @@
2630

2731
LetsPlot.setup_html()
2832

33+
# Theme tokens
34+
THEME = os.getenv("ANYPLOT_THEME", "light")
35+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
36+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
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+
41+
# Okabe-Ito palette (first series always #009E73)
42+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2"]
43+
44+
# Set seed for reproducibility
45+
np.random.seed(42)
46+
2947
# Load and prepare data
3048
iris = load_iris()
3149
X = iris.data
@@ -63,8 +81,12 @@
6381

6482
df_curves = pd.DataFrame(curves_data)
6583

66-
# Define colors for species - Python blue, yellow, and a third color
67-
species_colors = {"setosa": "#306998", "versicolor": "#FFD43B", "virginica": "#DC2626"}
84+
# Map species to Okabe-Ito colors
85+
species_colors = {
86+
target_names[0]: OKABE_ITO[0], # setosa: #009E73 (brand green)
87+
target_names[1]: OKABE_ITO[1], # versicolor: #D55E00 (vermillion)
88+
target_names[2]: OKABE_ITO[2], # virginica: #0072B2 (blue)
89+
}
6890

6991
# Create plot
7092
plot = (
@@ -75,23 +97,28 @@
7597
+ labs(
7698
x="Parameter t (radians)",
7799
y="Fourier Function Value",
78-
title="andrews-curves · letsplot · pyplots.ai",
100+
title="andrews-curves · letsplot · anyplot.ai",
79101
color="Species",
80102
)
81103
+ theme_minimal()
82104
+ theme(
83-
axis_title=element_text(size=20),
84-
axis_text=element_text(size=16),
85-
plot_title=element_text(size=24),
86-
legend_title=element_text(size=18),
87-
legend_text=element_text(size=16),
105+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
106+
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
107+
panel_grid_major=element_line(color=RULE, size=0.3),
108+
axis_title=element_text(size=20, color=INK),
109+
axis_text=element_text(size=16, color=INK_SOFT),
110+
axis_line=element_line(color=INK_SOFT, size=0.5),
111+
plot_title=element_text(size=24, color=INK),
112+
legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),
113+
legend_title=element_text(size=18, color=INK),
114+
legend_text=element_text(size=16, color=INK_SOFT),
88115
legend_position="right",
89116
)
90117
+ ggsize(1600, 900)
91118
)
92119

93120
# Save PNG (scale 3x to get 4800 × 2700 px)
94-
ggsave(plot, "plot.png", path=".", scale=3)
121+
ggsave(plot, f"plot-{THEME}.png", path=".", scale=3)
95122

96123
# Save HTML for interactivity
97-
ggsave(plot, "plot.html", path=".")
124+
ggsave(plot, f"plot-{THEME}.html", path=".")

0 commit comments

Comments
 (0)