|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | stem-basic: Basic Stem Plot |
3 | | -Library: bokeh 3.8.1 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: bokeh 3.9.0 | Python 3.13.13 |
| 4 | +Quality: 84/100 | Updated: 2026-04-30 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | +import sys |
| 9 | + |
| 10 | + |
| 11 | +sys.path = [p for p in sys.path if not p.endswith("/python")] |
| 12 | + |
7 | 13 | import numpy as np |
8 | 14 | from bokeh.io import export_png, output_file, save |
9 | 15 | from bokeh.models import ColumnDataSource |
10 | 16 | from bokeh.plotting import figure |
11 | 17 |
|
12 | 18 |
|
| 19 | +# Theme tokens |
| 20 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 21 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 22 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 23 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 24 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 25 | +BRAND = "#009E73" |
| 26 | + |
13 | 27 | # Data - Discrete signal samples (damped oscillation) |
14 | 28 | np.random.seed(42) |
15 | 29 | n_points = 30 |
16 | 30 | x = np.arange(n_points) |
17 | 31 | y = np.exp(-0.1 * x) * np.sin(0.5 * x) * 2 + np.random.randn(n_points) * 0.1 |
18 | 32 |
|
19 | | -# Baseline for stems |
20 | 33 | baseline = 0 |
21 | 34 |
|
22 | 35 | # Create data sources |
|
27 | 40 | p = figure( |
28 | 41 | width=4800, |
29 | 42 | height=2700, |
30 | | - title="stem-basic · bokeh · pyplots.ai", |
| 43 | + title="stem-basic · bokeh · anyplot.ai", |
31 | 44 | x_axis_label="Sample Index", |
32 | 45 | y_axis_label="Amplitude", |
33 | 46 | ) |
34 | 47 |
|
35 | 48 | # Draw stems (vertical lines from baseline to data points) |
36 | | -p.segment(x0="x0", y0="y0", x1="x1", y1="y1", source=stem_source, line_width=4, color="#306998", alpha=0.8) |
| 49 | +p.segment(x0="x0", y0="y0", x1="x1", y1="y1", source=stem_source, line_width=4, color=BRAND, alpha=0.85) |
37 | 50 |
|
38 | 51 | # Draw markers at data points |
39 | | -p.scatter(x="x", y="y", source=source, size=25, color="#306998", alpha=0.9) |
| 52 | +p.scatter(x="x", y="y", source=source, size=25, color=BRAND, alpha=1.0) |
40 | 53 |
|
41 | 54 | # Draw baseline |
42 | | -p.line( |
43 | | - x=[x.min() - 0.5, x.max() + 0.5], |
44 | | - y=[baseline, baseline], |
45 | | - line_width=3, |
46 | | - line_dash="dashed", |
47 | | - color="#999999", |
48 | | - alpha=0.6, |
49 | | -) |
| 55 | +p.line(x=[x.min() - 0.5, x.max() + 0.5], y=[baseline, baseline], line_width=3, color=INK_SOFT, alpha=0.6) |
50 | 56 |
|
51 | | -# Styling for 4800x2700 |
| 57 | +# Sizing |
52 | 58 | p.title.text_font_size = "36pt" |
53 | 59 | p.xaxis.axis_label_text_font_size = "28pt" |
54 | 60 | p.yaxis.axis_label_text_font_size = "28pt" |
55 | 61 | p.xaxis.major_label_text_font_size = "22pt" |
56 | 62 | p.yaxis.major_label_text_font_size = "22pt" |
57 | 63 |
|
58 | | -# Grid styling |
59 | | -p.grid.grid_line_alpha = 0.3 |
60 | | -p.grid.grid_line_dash = "dashed" |
| 64 | +# Theme-adaptive chrome |
| 65 | +p.background_fill_color = PAGE_BG |
| 66 | +p.border_fill_color = PAGE_BG |
| 67 | +p.outline_line_color = INK_SOFT |
| 68 | + |
| 69 | +p.title.text_color = INK |
| 70 | +p.xaxis.axis_label_text_color = INK |
| 71 | +p.yaxis.axis_label_text_color = INK |
| 72 | +p.xaxis.major_label_text_color = INK_SOFT |
| 73 | +p.yaxis.major_label_text_color = INK_SOFT |
| 74 | +p.xaxis.axis_line_color = INK_SOFT |
| 75 | +p.yaxis.axis_line_color = INK_SOFT |
| 76 | +p.xaxis.major_tick_line_color = INK_SOFT |
| 77 | +p.yaxis.major_tick_line_color = INK_SOFT |
| 78 | + |
| 79 | +p.xgrid.grid_line_color = INK |
| 80 | +p.ygrid.grid_line_color = INK |
| 81 | +p.xgrid.grid_line_alpha = 0.10 |
| 82 | +p.ygrid.grid_line_alpha = 0.10 |
61 | 83 |
|
62 | 84 | # Save outputs |
63 | | -export_png(p, filename="plot.png") |
64 | | -output_file("plot.html") |
| 85 | +export_png(p, filename=f"plot-{THEME}.png") |
| 86 | +output_file(f"plot-{THEME}.html") |
65 | 87 | save(p) |
0 commit comments