{"spec_id":"band-basic","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nband-basic: Basic Band Plot\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-29\n\"\"\"\n\nimport os\nimport time\nfrom pathlib import Path\n\nimport numpy as np\nfrom bokeh.io import output_file, save\nfrom bokeh.models import ColumnDataSource\nfrom bokeh.plotting import figure\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\n\n# Theme tokens (Imprint palette — see prompts/default-style-guide.md)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"]\n\n# Data - Solar irradiance forecast with 95% confidence interval\nnp.random.seed(42)\nhours = np.linspace(6, 20, 120)  # 6 AM to 8 PM\n\npeak_hour = 13.0\nirradiance = 850 * np.exp(-0.5 * ((hours - peak_hour) / 2.8) ** 2) + 50\n\n# Uncertainty tight at midday (clear sky), widens in afternoon (convective clouds)\nbase_uncertainty = 15 + 8 * np.abs(hours - peak_hour)\nafternoon_spike = 45 * np.clip((hours - 15) / 2, 0, 1) ** 1.5\nuncertainty = base_uncertainty + afternoon_spike\n\ny_upper = irradiance + 1.96 * uncertainty\ny_lower = np.maximum(irradiance - 1.96 * uncertainty, 0)\n\nsource = ColumnDataSource(data={\"hours\": hours, \"irradiance\": irradiance, \"y_upper\": y_upper, \"y_lower\": y_lower})\n\n# Plot\ntitle = \"Solar Irradiance Forecast · band-basic · python · bokeh · anyplot.ai\"\n\np = figure(\n    width=3200,\n    height=1800,\n    title=title,\n    x_axis_label=\"Hour of Day\",\n    y_axis_label=\"Solar Irradiance (W/m²)\",\n    toolbar_location=None,\n    min_border_bottom=160,\n    min_border_left=180,\n    min_border_top=110,\n    min_border_right=50,\n)\n\n# Confidence interval band — first series → Imprint position 1\n# Higher alpha in dark theme: alpha=0.25 on #1A1A17 composites to near-invisible forest-green\nband_alpha = 0.38 if THEME == \"dark\" else 0.25\np.varea(\n    x=\"hours\",\n    y1=\"y_lower\",\n    y2=\"y_upper\",\n    source=source,\n    fill_color=IMPRINT_PALETTE[0],\n    fill_alpha=band_alpha,\n    legend_label=\"95% Confidence Interval\",\n)\n\n# Forecast mean line — second series → Imprint position 2\np.line(\n    x=\"hours\", y=\"irradiance\", source=source, line_color=IMPRINT_PALETTE[1], line_width=6, legend_label=\"Forecast Mean\"\n)\n\n# Theme-adaptive chrome\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = None\n\np.title.text_font_size = \"50pt\"\np.title.text_font_style = \"normal\"\np.title.text_color = INK\n\np.xaxis.axis_label_text_font_size = \"42pt\"\np.yaxis.axis_label_text_font_size = \"42pt\"\np.xaxis.axis_label_text_color = INK\np.yaxis.axis_label_text_color = INK\np.xaxis.axis_label_text_font_style = \"normal\"\np.yaxis.axis_label_text_font_style = \"normal\"\n\np.xaxis.major_label_text_font_size = \"34pt\"\np.yaxis.major_label_text_font_size = \"34pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.yaxis.major_label_text_color = INK_SOFT\n\np.xaxis.axis_line_color = INK_SOFT\np.yaxis.axis_line_color = INK_SOFT\np.xaxis.axis_line_width = 1\np.yaxis.axis_line_width = 1\n\np.xaxis.major_tick_line_color = None\np.yaxis.major_tick_line_color = None\np.xaxis.minor_tick_line_color = None\np.yaxis.minor_tick_line_color = None\n\n# Y-grid only (style guide: y-axis grid for line charts)\np.xgrid.grid_line_color = None\np.ygrid.grid_line_color = INK\np.ygrid.grid_line_alpha = 0.15\n\n# Legend\np.legend.label_text_font_size = \"34pt\"\np.legend.label_text_color = INK_SOFT\np.legend.location = \"top_right\"\np.legend.background_fill_color = ELEVATED_BG\np.legend.background_fill_alpha = 0.85\np.legend.border_line_color = INK_SOFT\np.legend.glyph_width = 60\np.legend.glyph_height = 40\np.legend.padding = 20\np.legend.spacing = 12\n\n# Save HTML artifact\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with headless Selenium — export_png not used (snap driver incompatible)\nW, H = 3200, 1800\nopts = Options()\nfor arg in (\n    \"--headless=new\",\n    \"--no-sandbox\",\n    \"--disable-dev-shm-usage\",\n    \"--disable-gpu\",\n    f\"--window-size={W},{H}\",\n    \"--hide-scrollbars\",\n):\n    opts.add_argument(arg)\ndriver = webdriver.Chrome(options=opts)\n# CDP override pins the viewport to exactly W×H at DPR=1, avoiding\n# headless-Chrome viewport-vs-window-size discrepancies\ndriver.execute_cdp_cmd(\n    \"Emulation.setDeviceMetricsOverride\", {\"width\": W, \"height\": H, \"deviceScaleFactor\": 1, \"mobile\": False}\n)\ndriver.get(f\"file://{Path(f'plot-{THEME}.html').resolve()}\")\ntime.sleep(3)\ndriver.save_screenshot(f\"plot-{THEME}.png\")\ndriver.quit()\n"}