|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | point-basic: Point Estimate Plot |
3 | | -Library: letsplot 4.8.2 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-30 |
| 3 | +Library: letsplot 4.9.0 | Python 3.13.13 |
| 4 | +Quality: 89/100 | Updated: 2026-05-11 |
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 |
|
11 | 13 |
|
12 | 14 | LetsPlot.setup_html() |
13 | 15 |
|
| 16 | +# Theme tokens |
| 17 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 18 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 19 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 20 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 21 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 22 | +RULE = "rgba(26,26,23,0.10)" if THEME == "light" else "rgba(240,239,232,0.10)" |
| 23 | + |
| 24 | +BRAND = "#009E73" |
| 25 | + |
14 | 26 | # Data - Research study results with confidence intervals |
15 | 27 | np.random.seed(42) |
16 | 28 | categories = ["Treatment A", "Treatment B", "Treatment C", "Control", "Placebo"] |
17 | 29 | estimates = [4.2, 5.8, 3.1, 2.5, 1.8] |
18 | | -# Generate realistic confidence intervals (narrower for larger effects) |
19 | 30 | ci_width = [0.9, 1.1, 0.7, 0.8, 0.6] |
20 | | -lower = [e - w for e, w in zip(estimates, ci_width)] |
21 | | -upper = [e + w for e, w in zip(estimates, ci_width)] |
| 31 | +lower = [e - w for e, w in zip(estimates, ci_width, strict=False)] |
| 32 | +upper = [e + w for e, w in zip(estimates, ci_width, strict=False)] |
22 | 33 |
|
23 | 34 | df = pd.DataFrame({"group": categories, "estimate": estimates, "lower": lower, "upper": upper}) |
24 | 35 |
|
25 | 36 | # Plot - Horizontal point estimate plot with confidence intervals |
26 | 37 | plot = ( |
27 | 38 | ggplot(df, aes(x="group", y="estimate", ymin="lower", ymax="upper")) |
28 | | - + geom_pointrange(color="#306998", size=1.5, linewidth=1.5) |
29 | | - + geom_hline(yintercept=0, linetype="dashed", color="#666666", size=0.8, alpha=0.7) |
30 | | - + labs(y="Effect Size (95% CI)", x="Treatment Group", title="point-basic · lets-plot · pyplots.ai") |
| 39 | + + geom_pointrange(color=BRAND, size=1.5, linewidth=1.5) |
| 40 | + + geom_hline(yintercept=0, linetype="dashed", color=INK_SOFT, size=0.8, alpha=0.5) |
| 41 | + + labs(y="Effect Size (95% CI)", x="Treatment Group", title="point-basic · letsplot · anyplot.ai") |
31 | 42 | + coord_flip() |
32 | | - + theme_minimal() |
33 | 43 | + theme( |
34 | | - plot_title=element_text(size=24, face="bold"), |
35 | | - axis_title=element_text(size=20), |
36 | | - axis_text=element_text(size=16), |
37 | | - panel_grid_major_x=element_blank(), |
| 44 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 45 | + panel_background=element_rect(fill=PAGE_BG), |
| 46 | + panel_grid_major_x=element_line(color=RULE, size=0.3), |
38 | 47 | panel_grid_minor=element_blank(), |
| 48 | + panel_grid_major_y=element_blank(), |
| 49 | + axis_title=element_text(size=20, color=INK), |
| 50 | + axis_text=element_text(size=16, color=INK_SOFT), |
| 51 | + axis_line=element_line(color=INK_SOFT, size=0.5), |
| 52 | + plot_title=element_text(size=24, color=INK), |
39 | 53 | ) |
40 | 54 | + ggsize(1600, 900) |
41 | 55 | ) |
42 | 56 |
|
43 | 57 | # Save |
44 | | -ggsave(plot, "plot.png", path=".", scale=3) |
45 | | - |
46 | | -# Save interactive HTML |
47 | | -ggsave(plot, "plot.html", path=".") |
| 58 | +ggsave(plot, f"plot-{THEME}.png", path=".", scale=3) |
| 59 | +ggsave(plot, f"plot-{THEME}.html", path=".") |
0 commit comments