{"spec_id":"line-stepwise","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nline-stepwise: Step Line Plot\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-13\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, HoverTool\nfrom bokeh.plotting import figure\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\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\"\nBRAND = \"#009E73\"\n\n# Data - CPU usage readings over time with discrete state changes\nnp.random.seed(42)\nn_points = 24\nhours = np.arange(n_points)\n\n# Realistic CPU usage that stays at levels then jumps\n# Removed random noise to better represent discrete state changes\ncpu_usage = np.array(\n    [35, 42, 55, 72, 85, 92, 88, 70, 55, 40, 32, 28, 35, 52, 78, 88, 95, 90, 75, 60, 48, 42, 32, 25], dtype=float\n)\n\n# Create step function data by duplicating points for post-step behavior\n# For 'post' step style: value changes after the point\nx_step = []\ny_step = []\nfor i in range(len(hours)):\n    x_step.append(hours[i])\n    y_step.append(cpu_usage[i])\n    if i < len(hours) - 1:\n        x_step.append(hours[i + 1])\n        y_step.append(cpu_usage[i])\n\n# Create data source for the step line\nsource = ColumnDataSource(data={\"x\": x_step, \"y\": y_step})\n\n# Create figure\np = figure(\n    width=4800,\n    height=2700,\n    title=\"line-stepwise · bokeh · anyplot.ai\",\n    x_axis_label=\"Hour of Day\",\n    y_axis_label=\"CPU Usage (%)\",\n)\n\n# Plot step line\np.line(x=\"x\", y=\"y\", source=source, line_width=4, line_color=BRAND, line_alpha=0.9)\n\n# Add markers at actual data points for clarity - larger for visibility\nmarker_source = ColumnDataSource(data={\"x\": hours, \"y\": cpu_usage})\np.scatter(x=\"x\", y=\"y\", source=marker_source, size=16, color=BRAND, alpha=0.9)\n\n# Add HoverTool for enhanced interactivity\nhover = HoverTool(tooltips=[(\"Hour\", \"@x{0}\"), (\"Usage\", \"@y{0.0}%\")])\np.add_tools(hover)\n\n# Style text sizes for large canvas\np.title.text_font_size = \"28pt\"\np.title.text_color = INK\np.xaxis.axis_label_text_font_size = \"22pt\"\np.xaxis.axis_label_text_color = INK\np.yaxis.axis_label_text_font_size = \"22pt\"\np.yaxis.axis_label_text_color = INK\np.xaxis.major_label_text_font_size = \"18pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.yaxis.major_label_text_font_size = \"18pt\"\np.yaxis.major_label_text_color = INK_SOFT\n\n# Theme-adaptive styling\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\n\n# Subtle grid with theme-adaptive colors\np.xaxis.axis_line_color = INK_SOFT\np.yaxis.axis_line_color = INK_SOFT\np.xaxis.major_tick_line_color = INK_SOFT\np.yaxis.major_tick_line_color = INK_SOFT\n\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# Legend styling if present\nif p.legend:\n    p.legend.background_fill_color = ELEVATED_BG\n    p.legend.border_line_color = INK_SOFT\n    p.legend.label_text_color = INK_SOFT\n\n# Axis ranges\np.y_range.start = 0\np.y_range.end = 105\n\n# Save as HTML\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with headless Chrome using Selenium\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"}