|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | import numpy as np |
9 | 11 | from sklearn.datasets import load_iris |
10 | 12 | from sklearn.preprocessing import StandardScaler |
11 | 13 |
|
12 | 14 |
|
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) |
14 | 25 | iris = load_iris() |
15 | 26 | X = iris.data |
16 | 27 | y = iris.target |
|
38 | 49 | # Compute all Andrews curves: each row of X_scaled dot basis.T gives one curve |
39 | 50 | curves = X_scaled @ basis.T # shape: (150, 200) |
40 | 51 |
|
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) |
46 | 55 |
|
47 | 56 | # Plot Andrews curves for each observation |
48 | 57 | 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) |
50 | 59 |
|
51 | 60 | # Create legend with sample lines |
52 | 61 | 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) |
54 | 74 |
|
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) |
62 | 82 |
|
63 | 83 | # Set x-axis ticks at meaningful positions |
64 | 84 | ax.set_xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi]) |
65 | 85 | ax.set_xticklabels(["-π", "-π/2", "0", "π/2", "π"], fontsize=16) |
66 | 86 |
|
67 | 87 | 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