|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | band-basic: Basic Band Plot |
3 | | -Library: bokeh 3.8.1 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: bokeh 3.8.2 | Python 3.14 |
| 4 | +Quality: /100 | Updated: 2026-02-23 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import numpy as np |
|
18 | 18 | y_upper = y_center + 1.96 * uncertainty # 95% CI upper bound |
19 | 19 | y_lower = y_center - 1.96 * uncertainty # 95% CI lower bound |
20 | 20 |
|
21 | | -# Create ColumnDataSource for band (patch requires closed polygon) |
22 | | -x_band = np.concatenate([x, x[::-1]]) |
23 | | -y_band = np.concatenate([y_upper, y_lower[::-1]]) |
24 | | -band_source = ColumnDataSource(data={"x": x_band, "y": y_band}) |
| 21 | +# Create ColumnDataSource |
| 22 | +source = ColumnDataSource(data={"x": x, "y_center": y_center, "y_upper": y_upper, "y_lower": y_lower}) |
25 | 23 |
|
26 | | -# Create ColumnDataSource for center line |
27 | | -line_source = ColumnDataSource(data={"x": x, "y": y_center}) |
28 | | - |
29 | | -# Create figure (4800 × 2700 px) |
30 | | -p = figure(width=4800, height=2700, title="band-basic · bokeh · pyplots.ai", x_axis_label="Time", y_axis_label="Value") |
| 24 | +# Create figure (4800 x 2700 px) |
| 25 | +p = figure( |
| 26 | + width=4800, |
| 27 | + height=2700, |
| 28 | + title="band-basic \u00b7 bokeh \u00b7 pyplots.ai", |
| 29 | + x_axis_label="Time (s)", |
| 30 | + y_axis_label="Value", |
| 31 | + toolbar_location=None, |
| 32 | +) |
31 | 33 |
|
32 | | -# Plot band (semi-transparent fill) |
33 | | -p.patch( |
| 34 | +# Plot band using varea (idiomatic Bokeh band glyph) |
| 35 | +p.varea( |
34 | 36 | x="x", |
35 | | - y="y", |
36 | | - source=band_source, |
| 37 | + y1="y_lower", |
| 38 | + y2="y_upper", |
| 39 | + source=source, |
37 | 40 | fill_color="#306998", |
38 | 41 | fill_alpha=0.3, |
39 | | - line_color="#306998", |
40 | | - line_alpha=0.5, |
41 | | - line_width=2, |
42 | 42 | legend_label="95% Confidence Interval", |
43 | 43 | ) |
44 | 44 |
|
45 | 45 | # Plot center line |
46 | | -p.line(x="x", y="y", source=line_source, line_color="#FFD43B", line_width=4, legend_label="Mean Trend") |
| 46 | +p.line(x="x", y="y_center", source=source, line_color="#FFD43B", line_width=6, legend_label="Mean Trend") |
| 47 | + |
| 48 | +# Styling for 4800x2700 px — Bokeh pt renders at CSS scale, need large values |
| 49 | +p.title.text_font_size = "96pt" |
| 50 | +p.title.text_font_style = "normal" |
| 51 | +p.xaxis.axis_label_text_font_size = "72pt" |
| 52 | +p.yaxis.axis_label_text_font_size = "72pt" |
| 53 | +p.xaxis.major_label_text_font_size = "56pt" |
| 54 | +p.yaxis.major_label_text_font_size = "56pt" |
| 55 | + |
| 56 | +# Remove top and right spines |
| 57 | +p.outline_line_color = None |
| 58 | +p.xaxis.axis_line_color = "#333333" |
| 59 | +p.yaxis.axis_line_color = "#333333" |
47 | 60 |
|
48 | | -# Styling for 4800×2700 px |
49 | | -p.title.text_font_size = "28pt" |
50 | | -p.xaxis.axis_label_text_font_size = "22pt" |
51 | | -p.yaxis.axis_label_text_font_size = "22pt" |
52 | | -p.xaxis.major_label_text_font_size = "18pt" |
53 | | -p.yaxis.major_label_text_font_size = "18pt" |
| 61 | +# Grid styling - subtle solid lines |
| 62 | +p.xgrid.grid_line_alpha = 0.15 |
| 63 | +p.ygrid.grid_line_alpha = 0.15 |
| 64 | +p.xgrid.grid_line_dash = "solid" |
| 65 | +p.ygrid.grid_line_dash = "solid" |
54 | 66 |
|
55 | | -# Grid styling |
56 | | -p.grid.grid_line_alpha = 0.3 |
57 | | -p.grid.grid_line_dash = [6, 4] |
| 67 | +# Remove tick marks, keep labels |
| 68 | +p.xaxis.major_tick_line_color = None |
| 69 | +p.yaxis.major_tick_line_color = None |
| 70 | +p.xaxis.minor_tick_line_color = None |
| 71 | +p.yaxis.minor_tick_line_color = None |
58 | 72 |
|
59 | 73 | # Legend styling |
60 | | -p.legend.label_text_font_size = "18pt" |
| 74 | +p.legend.label_text_font_size = "56pt" |
61 | 75 | p.legend.location = "top_left" |
62 | 76 | p.legend.background_fill_alpha = 0.7 |
| 77 | +p.legend.border_line_color = None |
| 78 | +p.legend.glyph_width = 60 |
| 79 | +p.legend.glyph_height = 40 |
| 80 | +p.legend.padding = 20 |
| 81 | +p.legend.spacing = 12 |
63 | 82 |
|
64 | 83 | # Save as PNG and HTML |
65 | 84 | export_png(p, filename="plot.png") |
66 | | -save(p, filename="plot.html", title="band-basic · bokeh · pyplots.ai") |
| 85 | +save(p, filename="plot.html", title="band-basic \u00b7 bokeh \u00b7 pyplots.ai") |
0 commit comments