|
1 | 1 | """ anyplot.ai |
2 | 2 | errorbar-basic: Basic Error Bar Plot |
3 | | -Library: letsplot 4.9.0 | Python 3.14.4 |
4 | | -Quality: 91/100 | Updated: 2026-04-25 |
| 3 | +Library: letsplot 4.11.0 | Python 3.13.14 |
| 4 | +Quality: 89/100 | Updated: 2026-06-30 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import os |
|
32 | 32 | PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
33 | 33 | INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
34 | 34 | INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 35 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 36 | +RULE = "#1A1A1726" if THEME == "light" else "#F0EFE826" # 15% opacity — subtle grid |
35 | 37 |
|
36 | | -BRAND = "#009E73" # Okabe-Ito position 1 |
37 | | -FOCAL = "#C475FD" # Okabe-Ito position 2 — emphasises group with largest spread |
| 38 | +BRAND = "#009E73" # Imprint palette position 1 |
| 39 | +FOCAL = "#C475FD" # Imprint palette position 2 — highlights group with largest spread |
38 | 40 |
|
39 | | -# Data — experimental measurements with uncertainty |
| 41 | +# Data — clinical measurements comparing control vs treatment groups |
40 | 42 | data = pd.DataFrame( |
41 | 43 | { |
42 | 44 | "experiment": ["Control", "Treatment A", "Treatment B", "Treatment C", "Treatment D"], |
|
47 | 49 | data["ymin"] = data["mean_value"] - data["error"] |
48 | 50 | data["ymax"] = data["mean_value"] + data["error"] |
49 | 51 |
|
50 | | -# Highlight the group with the largest error spread to give the chart a focal point |
51 | 52 | focal_idx = data["error"].idxmax() |
52 | 53 | data["highlight"] = ["focal" if i == focal_idx else "base" for i in data.index] |
53 | 54 |
|
54 | 55 | color_map = {"base": BRAND, "focal": FOCAL} |
55 | 56 |
|
| 57 | +title = "errorbar-basic · python · letsplot · anyplot.ai" |
| 58 | +subtitle = ( |
| 59 | + "Treatment D (highlighted) has the widest error margin (±7.1 mg/dL), indicating higher measurement variability" |
| 60 | +) |
| 61 | + |
56 | 62 | anyplot_theme = theme( |
57 | 63 | plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
58 | 64 | panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
59 | 65 | panel_border=element_blank(), |
60 | 66 | panel_grid_major_x=element_blank(), |
61 | 67 | panel_grid_minor=element_blank(), |
62 | | - panel_grid_major_y=element_line(color=INK_SOFT, size=0.3), |
| 68 | + panel_grid_major_y=element_line(color=RULE, size=0.3), |
63 | 69 | axis_line=element_line(color=INK_SOFT), |
64 | 70 | axis_ticks=element_line(color=INK_SOFT), |
65 | | - axis_title=element_text(color=INK, size=20), |
66 | | - axis_text=element_text(color=INK_SOFT, size=16), |
67 | | - plot_title=element_text(color=INK, size=24), |
| 71 | + axis_title=element_text(color=INK, size=12), |
| 72 | + axis_text=element_text(color=INK_SOFT, size=10), |
| 73 | + plot_title=element_text(color=INK, size=16), |
| 74 | + plot_subtitle=element_text(color=INK_SOFT, size=11), |
68 | 75 | legend_position="none", |
69 | 76 | ) |
70 | 77 |
|
|
73 | 80 | + geom_errorbar(aes(ymin="ymin", ymax="ymax"), width=0.3, size=1.5) |
74 | 81 | + geom_point(size=6) |
75 | 82 | + scale_color_manual(values=color_map) |
76 | | - + labs(x="Experimental Group", y="Measured Value (mg/dL)", title="errorbar-basic · letsplot · anyplot.ai") |
| 83 | + + labs(x="Experimental Group", y="Measured Value (mg/dL)", title=title, subtitle=subtitle) |
77 | 84 | + theme_minimal() |
78 | 85 | + anyplot_theme |
79 | | - + ggsize(1600, 900) |
| 86 | + + ggsize(800, 450) |
80 | 87 | ) |
81 | 88 |
|
82 | | -# PNG (scale 3x for 4800 x 2700 px) |
83 | | -ggsave(plot, f"plot-{THEME}.png", scale=3, path=".") |
| 89 | +# PNG (scale=4 → 3200 × 1800 px) |
| 90 | +ggsave(plot, f"plot-{THEME}.png", scale=4, path=".") |
84 | 91 |
|
85 | 92 | # HTML (interactive) |
86 | 93 | ggsave(plot, f"plot-{THEME}.html", path=".") |
0 commit comments