|
1 | | -""" anyplot.ai |
| 1 | +"""anyplot.ai |
2 | 2 | ecdf-basic: Basic ECDF Plot |
3 | | -Library: letsplot 4.9.0 | Python 3.14.4 |
4 | | -Quality: 87/100 | Updated: 2026-04-24 |
| 3 | +Library: letsplot | Python 3.14 |
| 4 | +Quality: pending | Created: 2026-06-25 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import os |
|
18 | 18 | ggplot, |
19 | 19 | ggsize, |
20 | 20 | labs, |
| 21 | + layer_tooltips, |
21 | 22 | scale_y_continuous, |
22 | 23 | stat_ecdf, |
23 | 24 | theme, |
|
31 | 32 | # Theme tokens |
32 | 33 | THEME = os.getenv("ANYPLOT_THEME", "light") |
33 | 34 | PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 35 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
34 | 36 | INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
35 | 37 | INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
36 | | -GRID = "#C9C7C1" if THEME == "light" else "#565551" |
| 38 | +# Imprint palette — grid at ~15% opacity, pre-blended with PAGE_BG |
| 39 | +GRID = "#D8D7D0" if THEME == "light" else "#3A3A36" |
37 | 40 | BRAND = "#009E73" |
38 | 41 |
|
39 | | -# Data — Web service response times (ms) with mixed distribution |
| 42 | +# Data — web service response times (ms) with bimodal distribution |
40 | 43 | np.random.seed(42) |
41 | 44 | response_times = np.concatenate( |
42 | 45 | [np.random.exponential(scale=50, size=150), np.random.normal(loc=200, scale=30, size=50)] |
43 | 46 | ) |
44 | 47 | df = pd.DataFrame({"response_time": response_times}) |
45 | 48 |
|
46 | | -# Plot — ECDF using stat_ecdf with step geometry |
| 49 | +# Title — 3-part format, 44 chars (< 67 baseline, no scaling needed) |
| 50 | +title = "ecdf-basic · python · letsplot · anyplot.ai" |
| 51 | + |
| 52 | +# Plot — ECDF step function with interactive tooltips (lets-plot HTML capability) |
47 | 53 | plot = ( |
48 | 54 | ggplot(df, aes(x="response_time")) |
49 | | - + stat_ecdf(geom="step", color=BRAND, size=2) |
50 | | - + labs( |
51 | | - x="Response Time (ms)", |
52 | | - y="Cumulative Proportion", |
53 | | - title="Web Service Response Times · ecdf-basic · letsplot · anyplot.ai", |
| 55 | + + stat_ecdf( |
| 56 | + geom="step", color=BRAND, size=1.5, tooltips=layer_tooltips().line("Response Time: @response_time{,.0f} ms") |
54 | 57 | ) |
| 58 | + + labs(x="Response Time (ms)", y="Cumulative Proportion", title=title) |
55 | 59 | + scale_y_continuous(limits=[0, 1], breaks=[0, 0.25, 0.5, 0.75, 1.0]) |
56 | | - + ggsize(1600, 900) |
| 60 | + + ggsize(800, 450) |
57 | 61 | + theme_minimal() |
58 | 62 | + theme( |
59 | 63 | plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
60 | 64 | panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
61 | | - legend_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
62 | | - panel_grid_major=element_line(color=GRID, size=0.6), |
| 65 | + legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT), |
| 66 | + panel_grid_major=element_line(color=GRID, size=0.5), |
63 | 67 | panel_grid_minor=element_blank(), |
64 | 68 | axis_line=element_line(color=INK_SOFT, size=0.6), |
65 | 69 | axis_ticks=element_line(color=INK_SOFT, size=0.5), |
66 | | - axis_text=element_text(size=16, color=INK_SOFT), |
67 | | - axis_title=element_text(size=20, color=INK), |
68 | | - plot_title=element_text(size=24, color=INK), |
| 70 | + axis_text=element_text(size=10, color=INK_SOFT), |
| 71 | + axis_title=element_text(size=12, color=INK), |
| 72 | + plot_title=element_text(size=16, color=INK), |
69 | 73 | ) |
70 | 74 | ) |
71 | 75 |
|
72 | 76 | # Save |
73 | | -ggsave(plot, filename=f"plot-{THEME}.png", path=".", scale=3) |
| 77 | +ggsave(plot, filename=f"plot-{THEME}.png", path=".", scale=4) |
74 | 78 | ggsave(plot, filename=f"plot-{THEME}.html", path=".") |
0 commit comments