Skip to content

Commit 1ddb101

Browse files
feat(matplotlib): implement andrews-curves (#6818)
## Implementation: `andrews-curves` - python/matplotlib Implements the **python/matplotlib** version of `andrews-curves`. **File:** `plots/andrews-curves/implementations/python/matplotlib.py` **Parent Issue:** #2859 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25918654244)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1fa3cc5 commit 1ddb101

2 files changed

Lines changed: 215 additions & 149 deletions

File tree

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

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
andrews-curves: Andrews Curves for Multivariate Data
3-
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-30
3+
Library: matplotlib 3.10.9 | Python 3.13.13
4+
Quality: 90/100 | Updated: 2026-05-15
55
"""
66

7+
import os
8+
79
import matplotlib.pyplot as plt
810
import numpy as np
911
from sklearn.datasets import load_iris
1012
from sklearn.preprocessing import StandardScaler
1113

1214

13-
# Load and prepare data
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
BRAND = "#009E73"
21+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2"]
22+
23+
# Data
24+
np.random.seed(42)
1425
iris = load_iris()
1526
X = iris.data
1627
y = iris.target
@@ -38,31 +49,40 @@
3849
# Compute all Andrews curves: each row of X_scaled dot basis.T gives one curve
3950
curves = X_scaled @ basis.T # shape: (150, 200)
4051

41-
# Create plot
42-
fig, ax = plt.subplots(figsize=(16, 9))
43-
44-
# Colors for each species (Python Blue, Python Yellow, and a complementary color)
45-
colors = ["#306998", "#FFD43B", "#E06C75"]
52+
# Plot
53+
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
54+
ax.set_facecolor(PAGE_BG)
4655

4756
# Plot Andrews curves for each observation
4857
for i in range(len(curves)):
49-
ax.plot(t, curves[i], color=colors[y[i]], alpha=0.4, linewidth=1.5)
58+
ax.plot(t, curves[i], color=OKABE_ITO[y[i]], alpha=0.4, linewidth=2.5)
5059

5160
# Create legend with sample lines
5261
for idx, species in enumerate(species_names):
53-
ax.plot([], [], color=colors[idx], linewidth=3, label=species, alpha=0.8)
62+
ax.plot([], [], color=OKABE_ITO[idx], linewidth=3, label=species, alpha=0.4)
63+
64+
# Style
65+
ax.set_xlabel("t (radians)", fontsize=20, color=INK)
66+
ax.set_ylabel("f(t)", fontsize=20, color=INK)
67+
ax.set_title("andrews-curves · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK)
68+
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT)
69+
ax.spines["top"].set_visible(False)
70+
ax.spines["right"].set_visible(False)
71+
for s in ("left", "bottom"):
72+
ax.spines[s].set_color(INK_SOFT)
73+
ax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)
5474

55-
# Styling
56-
ax.set_xlabel("t (radians)", fontsize=20)
57-
ax.set_ylabel("f(t)", fontsize=20)
58-
ax.set_title("andrews-curves · matplotlib · pyplots.ai", fontsize=24)
59-
ax.tick_params(axis="both", labelsize=16)
60-
ax.legend(fontsize=16, loc="upper right")
61-
ax.grid(True, alpha=0.3, linestyle="--")
75+
# Legend styling
76+
leg = ax.legend(fontsize=16, loc="upper right")
77+
if leg:
78+
leg.get_frame().set_facecolor(ELEVATED_BG)
79+
leg.get_frame().set_edgecolor(INK_SOFT)
80+
leg.get_frame().set_linewidth(0.8)
81+
plt.setp(leg.get_texts(), color=INK_SOFT)
6282

6383
# Set x-axis ticks at meaningful positions
6484
ax.set_xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi])
6585
ax.set_xticklabels(["-π", "-π/2", "0", "π/2", "π"], fontsize=16)
6686

6787
plt.tight_layout()
68-
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
88+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)

0 commit comments

Comments
 (0)