|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import numpy as np |
8 | 10 | 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 | +) |
10 | 23 | from sklearn.datasets import load_iris |
11 | 24 | from sklearn.preprocessing import StandardScaler |
12 | 25 |
|
13 | 26 |
|
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 |
15 | 37 | iris = load_iris() |
16 | 38 | X = iris.data |
17 | 39 | y = iris.target |
|
43 | 65 |
|
44 | 66 | df = pd.DataFrame(plot_data) |
45 | 67 |
|
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 | +) |
48 | 82 |
|
49 | | -# Create plot |
| 83 | +# Plot |
50 | 84 | plot = ( |
51 | 85 | ggplot(df, aes(x="t", y="value", color="species", group="observation")) |
52 | 86 | + 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) |
55 | 89 | + 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)) |
65 | 92 | ) |
66 | 93 |
|
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