{"spec_id":"sparkline-basic","library":"bokeh","language":"python","code":"\"\"\"anyplot.ai\nsparkline-basic: Basic Sparkline\nLibrary: bokeh 3.8.1 | Python 3.13.11\nQuality: 90/100 | Updated: 2026-05-02\n\"\"\"\n\nimport os\n\nimport numpy as np\nfrom bokeh.io import export_png, output_file, save\nfrom bokeh.models import ColumnDataSource\nfrom bokeh.plotting import figure\n\n\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Okabe-Ito categorical palette — identical across themes; only chrome flips.\nLINE_COLOR = \"#009E73\"\nMIN_COLOR = \"#C475FD\"\nMAX_COLOR = \"#009E73\"\n\n# Data — daily web-traffic sessions over 60 days, with a launch bump,\n# a mid-month decline, and weekend dips. Mixes ups and downs so the\n# sparkline shape is informative.\nnp.random.seed(42)\nn_points = 60\nday = np.arange(n_points)\ntrend = 100 + 0.6 * day\nlaunch_bump = 25 * np.exp(-((day - 12) ** 2) / 30.0)\nmid_decline = -22 * np.exp(-((day - 35) ** 2) / 60.0)\nweekend = np.where(day % 7 >= 5, -10.0, 0.0)\nnoise = np.random.randn(n_points) * 4\nvalues = trend + launch_bump + mid_decline + weekend + noise\n\nmin_idx = int(np.argmin(values))\nmax_idx = int(np.argmax(values))\n\nline_source = ColumnDataSource(data={\"x\": day, \"y\": values})\nendpoint_source = ColumnDataSource(data={\"x\": [day[0], day[-1]], \"y\": [values[0], values[-1]]})\nextreme_source = ColumnDataSource(\n    data={\"x\": [day[min_idx], day[max_idx]], \"y\": [values[min_idx], values[max_idx]], \"color\": [MIN_COLOR, MAX_COLOR]}\n)\n\n# Compact ~4:1 sparkline canvas\np = figure(width=4800, height=1200, title=\"sparkline-basic · bokeh · anyplot.ai\", toolbar_location=None)\n\n# Strip all chart chrome — sparkline minimalism\np.xaxis.visible = False\np.yaxis.visible = False\np.xgrid.visible = False\np.ygrid.visible = False\np.outline_line_color = None\np.min_border = 80\n\n# Theme-adaptive chrome (data colors stay identical across themes)\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.title.text_color = INK\np.title.text_font_size = \"32pt\"\np.title.align = \"center\"\n\n# Sparkline geometry\np.line(x=\"x\", y=\"y\", source=line_source, line_width=6, color=LINE_COLOR, alpha=0.95)\np.scatter(x=\"x\", y=\"y\", source=endpoint_source, size=22, color=INK_SOFT, alpha=0.7)\np.scatter(x=\"x\", y=\"y\", source=extreme_source, size=44, color=\"color\", alpha=0.95)\n\nexport_png(p, filename=f\"plot-{THEME}.png\")\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n"}