|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | errorbar-basic: Basic Error Bar Plot |
3 | | -Library: matplotlib 3.10.8 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-23 |
| 3 | +Library: matplotlib 3.10.9 | Python 3.14.4 |
| 4 | +Quality: 86/100 | Updated: 2026-04-25 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | import numpy as np |
9 | 11 |
|
10 | 12 |
|
| 13 | +# Theme tokens |
| 14 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 15 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 16 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 17 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 18 | +BRAND = "#009E73" # Okabe-Ito position 1 |
| 19 | + |
11 | 20 | # Data - experimental measurements with associated uncertainties |
12 | 21 | np.random.seed(42) |
13 | 22 | categories = ["Control", "Treatment A", "Treatment B", "Treatment C", "Treatment D", "Treatment E"] |
14 | 23 | x = np.arange(len(categories)) |
15 | | -y = np.array([25.3, 38.7, 42.1, 35.8, 48.2, 31.5]) # Mean values |
| 24 | +y = np.array([25.3, 38.7, 42.1, 35.8, 48.2, 31.5]) |
16 | 25 |
|
17 | 26 | # Asymmetric errors: Treatment C and D have notably different lower/upper bounds |
18 | 27 | asymmetric_lower = np.array([2.1, 3.5, 2.8, 6.5, 4.8, 2.5]) |
19 | 28 | asymmetric_upper = np.array([2.1, 3.5, 2.8, 2.8, 2.2, 2.5]) |
20 | 29 |
|
21 | 30 | # Plot |
22 | | -fig, ax = plt.subplots(figsize=(16, 9)) |
| 31 | +fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG) |
| 32 | +ax.set_facecolor(PAGE_BG) |
23 | 33 |
|
24 | | -# Error bars with caps |
25 | 34 | ax.errorbar( |
26 | 35 | x, |
27 | 36 | y, |
28 | 37 | yerr=[asymmetric_lower, asymmetric_upper], |
29 | 38 | fmt="o", |
30 | 39 | markersize=15, |
31 | | - color="#306998", |
32 | | - ecolor="#306998", |
| 40 | + color=BRAND, |
| 41 | + ecolor=BRAND, |
33 | 42 | elinewidth=3, |
34 | 43 | capsize=10, |
35 | 44 | capthick=3, |
36 | | - alpha=0.9, |
| 45 | + markeredgecolor=PAGE_BG, |
| 46 | + markeredgewidth=1.2, |
| 47 | + alpha=0.95, |
37 | 48 | ) |
38 | 49 |
|
39 | | -# Styling |
40 | | -ax.set_xlabel("Experimental Group", fontsize=20) |
41 | | -ax.set_ylabel("Response Value (units)", fontsize=20) |
42 | | -ax.set_title("errorbar-basic · matplotlib · pyplots.ai", fontsize=24) |
| 50 | +# Style |
| 51 | +ax.set_xlabel("Experimental Group", fontsize=20, color=INK) |
| 52 | +ax.set_ylabel("Response Value (units)", fontsize=20, color=INK) |
| 53 | +ax.set_title("errorbar-basic · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK) |
43 | 54 | ax.set_xticks(x) |
44 | | -ax.set_xticklabels(categories, fontsize=16) |
45 | | -ax.tick_params(axis="y", labelsize=16) |
46 | | -ax.grid(True, alpha=0.3, linestyle="--", axis="y") |
47 | | - |
48 | | -# Add some vertical padding |
| 55 | +ax.set_xticklabels(categories) |
| 56 | +ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT) |
| 57 | +ax.spines["top"].set_visible(False) |
| 58 | +ax.spines["right"].set_visible(False) |
| 59 | +for s in ("left", "bottom"): |
| 60 | + ax.spines[s].set_color(INK_SOFT) |
| 61 | +ax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK) |
| 62 | +ax.set_axisbelow(True) |
49 | 63 | ax.set_ylim(0, max(y + asymmetric_upper) * 1.15) |
50 | 64 |
|
51 | 65 | plt.tight_layout() |
52 | | -plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
| 66 | +plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG) |
0 commit comments