|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | learning-curve-basic: Model Learning Curve |
3 | | -Library: letsplot 4.8.2 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-26 |
| 3 | +Library: letsplot 4.9.0 | Python 3.13.13 |
| 4 | +Quality: 90/100 | Updated: 2026-05-10 |
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 * # noqa: F403 |
|
12 | 14 |
|
13 | 15 | LetsPlot.setup_html() # noqa: F405 |
14 | 16 |
|
| 17 | +# Theme tokens |
| 18 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 19 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 20 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 21 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 22 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 23 | + |
| 24 | +# Okabe-Ito palette (first series always #009E73) |
| 25 | +OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7", "#E69F00", "#56B4E9", "#F0E442"] |
| 26 | + |
15 | 27 | # Data - Simulate learning curve for a model showing slight overfitting pattern |
16 | 28 | np.random.seed(42) |
17 | 29 |
|
|
72 | 84 | + geom_ribbon(aes(ymin="Lower", ymax="Upper"), alpha=0.2, color="rgba(0,0,0,0)") |
73 | 85 | + geom_line(size=2) |
74 | 86 | + geom_point(size=4) |
75 | | - + scale_color_manual(values=["#306998", "#FFD43B"]) |
76 | | - + scale_fill_manual(values=["#306998", "#FFD43B"]) |
| 87 | + + scale_color_manual(values=OKABE_ITO[:2]) |
| 88 | + + scale_fill_manual(values=OKABE_ITO[:2]) |
77 | 89 | + scale_y_continuous(limits=[0.55, 1.02]) |
78 | 90 | + scale_x_continuous(limits=[0, 1700], breaks=list(range(0, 1800, 200))) |
79 | 91 | + labs( |
80 | 92 | x="Training Set Size (samples)", |
81 | | - y="Accuracy Score", |
82 | | - title="learning-curve-basic · letsplot · pyplots.ai", |
| 93 | + y="Accuracy Score (0-1)", |
| 94 | + title="learning-curve-basic · letsplot · anyplot.ai", |
83 | 95 | color="", |
84 | 96 | fill="", |
85 | 97 | ) |
86 | 98 | + theme_minimal() |
87 | 99 | + theme( |
88 | | - plot_title=element_text(size=24), |
89 | | - axis_title=element_text(size=20), |
90 | | - axis_text=element_text(size=16), |
91 | | - legend_text=element_text(size=16), |
92 | | - legend_position="bottom", |
93 | | - panel_grid_major=element_line(color="#CCCCCC", size=0.5), |
| 100 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 101 | + panel_background=element_rect(fill=PAGE_BG), |
| 102 | + panel_grid_major=element_line(color=INK_SOFT, size=0.3), |
94 | 103 | panel_grid_minor=element_blank(), |
| 104 | + axis_title=element_text(color=INK, size=20), |
| 105 | + axis_text=element_text(color=INK_SOFT, size=16), |
| 106 | + axis_line=element_line(color=INK_SOFT), |
| 107 | + plot_title=element_text(color=INK, size=24), |
| 108 | + legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT), |
| 109 | + legend_text=element_text(color=INK_SOFT, size=16), |
| 110 | + legend_title=element_text(color=INK), |
| 111 | + legend_position="bottom", |
95 | 112 | ) |
96 | 113 | + ggsize(1600, 900) |
97 | 114 | ) |
98 | 115 |
|
99 | 116 | # Save as PNG (scale 3x = 4800 x 2700 px) and HTML |
100 | | -ggsave(plot, "plot.png", path=".", scale=3) |
101 | | -ggsave(plot, "plot.html", path=".") |
| 117 | +ggsave(plot, f"plot-{THEME}.png", path=".", scale=3) |
| 118 | +ggsave(plot, f"plot-{THEME}.html", path=".") |
0 commit comments