{"spec_id":"line-styled","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nline-styled: Styled Line Plot\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 94/100 | Updated: 2026-05-12\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, Legend\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\"\n\n# Okabe-Ito palette\nIMPRINT = [\n    \"#009E73\",  # bluish green (brand)\n    \"#C475FD\",  # vermillion\n    \"#4467A3\",  # blue\n    \"#BD8233\",  # reddish purple\n]\n\n# Data - Monthly performance metrics over a year\nnp.random.seed(42)\nmonths = np.arange(1, 13)\n\n# Generate realistic trending data for different metrics\nbase = np.array([65, 68, 72, 75, 78, 82, 85, 84, 80, 77, 74, 70])\ncpu_usage = base + np.random.randn(12) * 3\nmemory_usage = base * 0.85 + np.random.randn(12) * 4 + 10\ndisk_io = base * 0.7 + np.random.randn(12) * 5 + 20\nnetwork = base * 1.1 + np.random.randn(12) * 2 - 5\n\n# Create ColumnDataSource\nsource = ColumnDataSource(\n    data={\"month\": months, \"cpu\": cpu_usage, \"memory\": memory_usage, \"disk\": disk_io, \"network\": network}\n)\n\n# Create figure (4800 × 2700 px)\np = figure(\n    width=4800,\n    height=2700,\n    title=\"line-styled · bokeh · anyplot.ai\",\n    x_axis_label=\"Month\",\n    y_axis_label=\"Utilization (%)\",\n)\n\n# Define line styles and colors\nline_styles = [\"solid\", [20, 10], [4, 8], [20, 8, 4, 8]]\nseries_names = [\"CPU Usage\", \"Memory Usage\", \"Disk I/O\", \"Network Traffic\"]\ny_columns = [\"cpu\", \"memory\", \"disk\", \"network\"]\n\n# Create legend items\nlegend_items = []\n\nfor col, style, color, name in zip(y_columns, line_styles, IMPRINT, series_names, strict=True):\n    # Add line with appropriate style\n    line = p.line(x=\"month\", y=col, source=source, line_width=6, color=color, line_dash=style)\n\n    # Add scatter points for better visibility\n    scatter = p.scatter(x=\"month\", y=col, source=source, size=25, color=color, alpha=0.9)\n\n    legend_items.append((name, [line, scatter]))\n\n# Create and configure legend\nlegend = Legend(items=legend_items, location=\"top_left\")\nlegend.label_text_font_size = \"28pt\"\nlegend.label_text_color = INK_SOFT\nlegend.glyph_height = 40\nlegend.glyph_width = 80\nlegend.spacing = 15\nlegend.padding = 20\nlegend.background_fill_alpha = 0.95\nlegend.background_fill_color = ELEVATED_BG\nlegend.border_line_color = INK_SOFT\nlegend.border_line_width = 2\np.add_layout(legend, \"center\")\n\n# Style configuration - larger fonts for 4800x2700 canvas\np.title.text_font_size = \"48pt\"\np.title.text_color = INK\np.title.align = \"center\"\np.xaxis.axis_label_text_font_size = \"36pt\"\np.yaxis.axis_label_text_font_size = \"36pt\"\np.xaxis.axis_label_text_color = INK\np.yaxis.axis_label_text_color = INK\np.xaxis.major_label_text_font_size = \"28pt\"\np.yaxis.major_label_text_font_size = \"28pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.yaxis.major_label_text_color = INK_SOFT\n\n# Grid styling\np.grid.grid_line_alpha = 0.10\np.grid.grid_line_color = INK\np.xgrid.grid_line_alpha = 0.10\np.ygrid.grid_line_alpha = 0.10\n\n# Axis styling\np.xaxis.ticker = list(range(1, 13))\np.xaxis.major_label_overrides = {\n    1: \"Jan\",\n    2: \"Feb\",\n    3: \"Mar\",\n    4: \"Apr\",\n    5: \"May\",\n    6: \"Jun\",\n    7: \"Jul\",\n    8: \"Aug\",\n    9: \"Sep\",\n    10: \"Oct\",\n    11: \"Nov\",\n    12: \"Dec\",\n}\n\n# Background and outline\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\n\n# Axis line styling\np.xaxis.axis_line_color = INK_SOFT\np.yaxis.axis_line_color = INK_SOFT\np.xaxis.axis_line_width = 2\np.yaxis.axis_line_width = 2\np.xaxis.major_tick_line_color = INK_SOFT\np.yaxis.major_tick_line_color = INK_SOFT\np.xaxis.major_tick_line_width = 2\np.yaxis.major_tick_line_width = 2\n\n# Save as HTML\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with Selenium (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)\n\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"}