|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import numpy as np |
8 | 10 | import pandas as pd |
9 | 11 | from lets_plot import ( |
10 | 12 | LetsPlot, |
11 | 13 | aes, |
| 14 | + element_line, |
| 15 | + element_rect, |
12 | 16 | element_text, |
13 | 17 | geom_line, |
14 | 18 | ggplot, |
|
26 | 30 |
|
27 | 31 | LetsPlot.setup_html() |
28 | 32 |
|
| 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 | + |
29 | 47 | # Load and prepare data |
30 | 48 | iris = load_iris() |
31 | 49 | X = iris.data |
|
63 | 81 |
|
64 | 82 | df_curves = pd.DataFrame(curves_data) |
65 | 83 |
|
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 | +} |
68 | 90 |
|
69 | 91 | # Create plot |
70 | 92 | plot = ( |
|
75 | 97 | + labs( |
76 | 98 | x="Parameter t (radians)", |
77 | 99 | y="Fourier Function Value", |
78 | | - title="andrews-curves · letsplot · pyplots.ai", |
| 100 | + title="andrews-curves · letsplot · anyplot.ai", |
79 | 101 | color="Species", |
80 | 102 | ) |
81 | 103 | + theme_minimal() |
82 | 104 | + 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), |
88 | 115 | legend_position="right", |
89 | 116 | ) |
90 | 117 | + ggsize(1600, 900) |
91 | 118 | ) |
92 | 119 |
|
93 | 120 | # 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) |
95 | 122 |
|
96 | 123 | # Save HTML for interactivity |
97 | | -ggsave(plot, "plot.html", path=".") |
| 124 | +ggsave(plot, f"plot-{THEME}.html", path=".") |
0 commit comments