Skip to content

Commit f5af918

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

2 files changed

Lines changed: 215 additions & 163 deletions

File tree

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
andrews-curves: Andrews Curves for Multivariate Data
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-30
3+
Library: altair 6.1.0 | Python 3.13.13
4+
Quality: 92/100 | Updated: 2026-05-15
55
"""
66

7-
import altair as alt
8-
import numpy as np
9-
import pandas as pd
10-
from sklearn.datasets import load_iris
11-
from sklearn.preprocessing import StandardScaler
7+
import os
8+
import sys
129

1310

14-
# Set random seed for reproducibility
15-
np.random.seed(42)
11+
# Remove script directory from sys.path to avoid importing local altair.py
12+
script_dir = os.path.dirname(os.path.abspath(__file__))
13+
if script_dir in sys.path:
14+
sys.path.remove(script_dir)
15+
16+
import altair as alt # noqa: E402
17+
import numpy as np # noqa: E402
18+
import pandas as pd # noqa: E402
19+
from sklearn.datasets import load_iris # noqa: E402
20+
from sklearn.preprocessing import StandardScaler # noqa: E402
21+
22+
23+
# Theme tokens
24+
THEME = os.getenv("ANYPLOT_THEME", "light")
25+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
26+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
27+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
28+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
29+
30+
# Okabe-Ito palette
31+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2"]
1632

1733
# Load and prepare data
34+
np.random.seed(42)
1835
iris = load_iris()
1936
X = iris.data
2037
y = iris.target
@@ -50,39 +67,56 @@
5067

5168
df = pd.DataFrame(curves_data)
5269

53-
# Define colors for species
54-
species_colors = ["#306998", "#FFD43B", "#6B8E23"]
55-
5670
# Create chart
5771
chart = (
5872
alt.Chart(df)
59-
.mark_line(opacity=0.4, strokeWidth=2)
73+
.mark_line(opacity=0.5, size=2)
6074
.encode(
61-
x=alt.X("t:Q", title="t (radians)", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
62-
y=alt.Y("value:Q", title="Andrews Curve Value", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
75+
x=alt.X(
76+
"t:Q",
77+
title="t (radians)",
78+
axis=alt.Axis(labelFontSize=18, titleFontSize=22, labelColor=INK_SOFT, titleColor=INK),
79+
),
80+
y=alt.Y(
81+
"value:Q",
82+
title="Andrews Curve Value",
83+
axis=alt.Axis(labelFontSize=18, titleFontSize=22, labelColor=INK_SOFT, titleColor=INK),
84+
),
6385
color=alt.Color(
6486
"species:N",
6587
title="Species",
66-
scale=alt.Scale(domain=["Setosa", "Versicolor", "Virginica"], range=species_colors),
67-
legend=alt.Legend(titleFontSize=22, labelFontSize=20),
88+
scale=alt.Scale(domain=species_names, range=OKABE_ITO),
89+
legend=alt.Legend(
90+
titleFontSize=18,
91+
labelFontSize=16,
92+
titleColor=INK,
93+
labelColor=INK_SOFT,
94+
fillColor=ELEVATED_BG,
95+
strokeColor=INK_SOFT,
96+
),
6897
),
6998
detail="observation:N",
99+
tooltip=["species:N", "observation:N"],
70100
)
71101
.properties(
72102
width=1600,
73103
height=900,
74-
title=alt.Title(
75-
"Iris Classification · andrews-curves · altair · pyplots.ai",
76-
fontSize=28,
77-
subtitle="Fourier series transformation of multivariate data for visual pattern comparison",
78-
subtitleFontSize=18,
79-
),
104+
background=PAGE_BG,
105+
title=alt.Title("andrews-curves · altair · anyplot.ai", fontSize=28, color=INK),
106+
)
107+
.configure_axis(domainColor=INK_SOFT, tickColor=INK_SOFT, gridColor=INK, gridOpacity=0.10)
108+
.configure_view(fill=PAGE_BG, stroke=None)
109+
.configure_title(color=INK)
110+
.configure_legend(
111+
titleFontSize=18,
112+
labelFontSize=16,
113+
titleColor=INK,
114+
labelColor=INK_SOFT,
115+
fillColor=ELEVATED_BG,
116+
strokeColor=INK_SOFT,
80117
)
81-
.configure_axis(labelFontSize=18, titleFontSize=22)
82-
.configure_view(strokeWidth=0)
83-
.configure_title(fontSize=28)
84118
)
85119

86120
# Save as PNG and HTML
87-
chart.save("plot.png", scale_factor=3.0)
88-
chart.save("plot.html")
121+
chart.save(f"plot-{THEME}.png", scale_factor=3.0)
122+
chart.save(f"plot-{THEME}.html")

0 commit comments

Comments
 (0)