{"spec_id":"histogram-stepwise","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nhistogram-stepwise: Step Histogram\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 96/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\nimport sys\nimport time\nfrom pathlib import Path\n\n# Remove the script's directory from sys.path to avoid circular import\nsys.path = [p for p in sys.path if not p.endswith(\"python\")]\n\nimport numpy as np\nfrom bokeh.io import output_file, save\nfrom bokeh.models import HoverTool\nfrom bokeh.plotting import figure\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\n# Theme tokens\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\n# Okabe-Ito palette (first series is always #009E73)\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\"]\n\n# Data - Two distributions with different spreads for comparison\nnp.random.seed(42)\ndata1 = np.random.normal(loc=50, scale=12, size=500)  # Temperature sensor A\ndata2 = np.random.normal(loc=65, scale=8, size=500)  # Temperature sensor B (tighter spread)\n\n# Compute histogram bins and counts\nbins = np.linspace(15, 100, 35)\ncounts1, edges1 = np.histogram(data1, bins=bins)\ncounts2, edges2 = np.histogram(data2, bins=bins)\n\n# Create step coordinates for step histogram (outline only)\nx1 = np.repeat(edges1, 2)[1:-1]\ny1 = np.repeat(counts1, 2)\nx2 = np.repeat(edges2, 2)[1:-1]\ny2 = np.repeat(counts2, 2)\n\n# Create figure\np = figure(\n    width=4800,\n    height=2700,\n    title=\"histogram-stepwise · bokeh · anyplot.ai\",\n    x_axis_label=\"Temperature (°C)\",\n    y_axis_label=\"Frequency\",\n    toolbar_location=\"right\",\n)\n\n# Plot step histograms with Okabe-Ito colors\nline1 = p.line(x1, y1, line_width=4, color=IMPRINT[0], legend_label=\"Sensor A\", alpha=0.85)\nline2 = p.line(x2, y2, line_width=4, color=IMPRINT[1], legend_label=\"Sensor B\", alpha=0.85)\n\n# Add hover tooltips for interactivity\nhover1 = HoverTool(renderers=[line1], tooltips=[(\"Temperature (°C)\", \"$x{0.0}\"), (\"Frequency\", \"$y{0}\")])\nhover2 = HoverTool(renderers=[line2], tooltips=[(\"Temperature (°C)\", \"$x{0.0}\"), (\"Frequency\", \"$y{0}\")])\np.add_tools(hover1, hover2)\n\n# Title styling\np.title.text_font_size = \"28pt\"\np.title.text_color = INK\n\n# Axis label styling\np.xaxis.axis_label_text_font_size = \"22pt\"\np.yaxis.axis_label_text_font_size = \"22pt\"\np.xaxis.axis_label_text_color = INK\np.yaxis.axis_label_text_color = INK\n\n# Tick label styling\np.xaxis.major_label_text_font_size = \"18pt\"\np.yaxis.major_label_text_font_size = \"18pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.yaxis.major_label_text_color = INK_SOFT\n\n# Grid styling (subtle)\np.xgrid.grid_line_color = INK\np.ygrid.grid_line_color = INK\np.xgrid.grid_line_alpha = 0.10\np.ygrid.grid_line_alpha = 0.10\n\n# Axis and border styling\np.axis.axis_line_color = INK_SOFT\np.axis.major_tick_line_color = INK_SOFT\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\n\n# Legend styling (improved visibility)\np.legend.label_text_font_size = \"20pt\"\np.legend.label_text_color = INK_SOFT\np.legend.background_fill_color = ELEVATED_BG\np.legend.border_line_color = INK_SOFT\np.legend.location = \"top_right\"\np.legend.padding = 20\np.legend.spacing = 15\np.legend.margin = 15\n\n# Save HTML\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with headless Chrome\nW, H = 4800, 2700\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)\ndriver.set_window_size(W, H)\ndriver.get(f\"file://{Path(f'plot-{THEME}.html').resolve()}\")\ntime.sleep(3)\ndriver.save_screenshot(f\"plot-{THEME}.png\")\ndriver.quit()\n"}