|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | strip-basic: Basic Strip Plot |
3 | | -Library: plotnine 0.15.2 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: plotnine 0.15.3 | Python 3.13.13 |
| 4 | +Quality: 85/100 | Updated: 2026-05-04 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import numpy as np |
8 | 10 | import pandas as pd |
9 | 11 | from plotnine import ( |
10 | 12 | aes, |
| 13 | + element_line, |
| 14 | + element_rect, |
11 | 15 | element_text, |
12 | 16 | geom_point, |
13 | 17 | ggplot, |
|
19 | 23 | ) |
20 | 24 |
|
21 | 25 |
|
| 26 | +# Theme tokens |
| 27 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 28 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 29 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 30 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 31 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 32 | + |
| 33 | +OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7"] |
| 34 | + |
22 | 35 | # Data - Patient response times (seconds) across different drug treatments |
23 | 36 | np.random.seed(42) |
24 | 37 |
|
25 | | -treatments = ["Placebo", "Drug A", "Drug B", "Drug C"] |
26 | | -data = [] |
27 | | - |
28 | | -# Generate varied distributions for each treatment group |
29 | 38 | distributions = { |
30 | 39 | "Placebo": {"mean": 45, "std": 12, "n": 40}, |
31 | 40 | "Drug A": {"mean": 32, "std": 8, "n": 45}, |
32 | 41 | "Drug B": {"mean": 28, "std": 10, "n": 42}, |
33 | 42 | "Drug C": {"mean": 25, "std": 6, "n": 38}, |
34 | 43 | } |
35 | 44 |
|
| 45 | +data = [] |
36 | 46 | for treatment, params in distributions.items(): |
37 | 47 | times = np.random.normal(params["mean"], params["std"], params["n"]) |
38 | | - # Clip to realistic response times (minimum 5 seconds) |
39 | 48 | times = np.clip(times, 5, 80) |
40 | 49 | data.extend([(treatment, time) for time in times]) |
41 | 50 |
|
42 | 51 | df = pd.DataFrame(data, columns=["treatment", "response_time"]) |
43 | 52 |
|
44 | | -# Create strip plot with jittered points |
| 53 | +# Plot |
45 | 54 | plot = ( |
46 | 55 | ggplot(df, aes(x="treatment", y="response_time", color="treatment")) |
47 | 56 | + geom_point(position=position_jitter(width=0.25, height=0, random_state=42), size=4, alpha=0.65) |
48 | | - + scale_color_manual(values=["#306998", "#FFD43B", "#4B8BBE", "#FFE873"]) |
49 | | - + labs(x="Treatment Group", y="Response Time (seconds)", title="strip-basic · plotnine · pyplots.ai") |
| 57 | + + scale_color_manual(values=OKABE_ITO) |
| 58 | + + labs(x="Treatment Group", y="Response Time (seconds)", title="strip-basic · plotnine · anyplot.ai") |
50 | 59 | + theme_minimal() |
51 | 60 | + theme( |
52 | 61 | figure_size=(16, 9), |
53 | | - text=element_text(size=14), |
54 | | - axis_title=element_text(size=20), |
55 | | - axis_text=element_text(size=16), |
56 | | - plot_title=element_text(size=24), |
| 62 | + plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG), |
| 63 | + panel_background=element_rect(fill=PAGE_BG), |
| 64 | + panel_grid_major=element_line(color=INK, size=0.3, alpha=0.20), |
| 65 | + panel_grid_minor=element_line(color=INK, size=0.15, alpha=0.08), |
| 66 | + axis_title=element_text(color=INK, size=20), |
| 67 | + axis_text=element_text(color=INK_SOFT, size=16), |
| 68 | + plot_title=element_text(color=INK, size=24), |
57 | 69 | legend_position="none", |
58 | 70 | ) |
59 | 71 | ) |
60 | 72 |
|
61 | 73 | # Save |
62 | | -plot.save("plot.png", dpi=300, verbose=False) |
| 74 | +plot.save(f"plot-{THEME}.png", dpi=300, verbose=False) |
0 commit comments