Skip to content

Commit c3fcd27

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

2 files changed

Lines changed: 204 additions & 155 deletions

File tree

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

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
andrews-curves: Andrews Curves for Multivariate Data
3-
Library: plotnine 0.15.2 | Python 3.13.11
4-
Quality: 94/100 | Created: 2025-12-30
3+
Library: plotnine 0.15.4 | Python 3.13.13
4+
Quality: 90/100 | Updated: 2026-05-15
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
9-
from plotnine import aes, element_text, geom_line, ggplot, labs, scale_color_manual, theme, theme_minimal
11+
from plotnine import (
12+
aes,
13+
element_line,
14+
element_rect,
15+
element_text,
16+
geom_line,
17+
ggplot,
18+
labs,
19+
scale_color_manual,
20+
theme,
21+
theme_minimal,
22+
)
1023
from sklearn.datasets import load_iris
1124
from sklearn.preprocessing import StandardScaler
1225

1326

14-
# Load iris dataset
27+
# Theme tokens
28+
THEME = os.getenv("ANYPLOT_THEME", "light")
29+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
30+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
31+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
32+
33+
# Okabe-Ito palette (first series is always #009E73)
34+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2"]
35+
36+
# Data
1537
iris = load_iris()
1638
X = iris.data
1739
y = iris.target
@@ -43,26 +65,31 @@
4365

4466
df = pd.DataFrame(plot_data)
4567

46-
# Distinct colors for the three species (blue, orange, green - colorblind-safe)
47-
colors = ["#1f77b4", "#ff7f0e", "#2ca02c"]
68+
# Theme-adaptive styling
69+
anyplot_theme = theme(
70+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
71+
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
72+
panel_grid_major=element_line(color=INK, size=0.3, alpha=0.10),
73+
panel_grid_minor=element_line(color=INK, size=0.2, alpha=0.05),
74+
panel_border=element_rect(color=INK_SOFT, fill=None),
75+
axis_title=element_text(size=20, color=INK),
76+
axis_text=element_text(size=16, color=INK_SOFT),
77+
axis_line=element_line(color=INK_SOFT),
78+
plot_title=element_text(size=24, color=INK),
79+
legend_text=element_text(size=16, color=INK_SOFT),
80+
legend_title=element_text(size=18, color=INK),
81+
)
4882

49-
# Create plot
83+
# Plot
5084
plot = (
5185
ggplot(df, aes(x="t", y="value", color="species", group="observation"))
5286
+ geom_line(alpha=0.4, size=0.8)
53-
+ labs(title="andrews-curves · plotnine · pyplots.ai", x="t (radians)", y="Andrews Curve Value", color="Species")
54-
+ scale_color_manual(values=colors)
87+
+ labs(title="andrews-curves · plotnine · anyplot.ai", x="t (radians)", y="Andrews Curve Value", color="Species")
88+
+ scale_color_manual(values=OKABE_ITO)
5589
+ theme_minimal()
56-
+ theme(
57-
figure_size=(16, 9),
58-
plot_title=element_text(size=24, weight="bold"),
59-
axis_title=element_text(size=20),
60-
axis_text=element_text(size=16),
61-
legend_title=element_text(size=18),
62-
legend_text=element_text(size=16),
63-
legend_position="right",
64-
)
90+
+ anyplot_theme
91+
+ theme(figure_size=(16, 9))
6592
)
6693

67-
# Save plot
68-
plot.save("plot.png", dpi=300, verbose=False)
94+
# Save
95+
plot.save(f"plot-{THEME}.png", dpi=300, verbose=False)

0 commit comments

Comments
 (0)