{"spec_id":"line-markers","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nline-markers: Line Plot with Markers\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 86/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\nimport sys\nimport time\nfrom pathlib import Path\n\nimport numpy as np\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\n\n# Handle import shadowing by temporarily removing current directory from path\nsaved_path = sys.path.copy()\nsys.path = [p for p in sys.path if not (p in (\"\", \".\") or p == os.getcwd())]\n\nfrom bokeh.io import output_file, save\nfrom bokeh.models import ColumnDataSource, Legend\nfrom bokeh.plotting import figure\n\n\n# Restore sys.path for the rest of script\nsys.path = saved_path\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# Data - Monthly temperature readings for three weather stations (°C)\nnp.random.seed(42)\nmonths = np.arange(1, 13)\nmonth_labels = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\n\n# Temperature patterns for different stations\nbase_temp = np.array([2, 4, 8, 12, 17, 21, 24, 23, 19, 13, 7, 3])\nstation_a = base_temp + np.random.randn(12) * 1.5\nstation_b = base_temp + 3 + np.random.randn(12) * 1.5\nstation_c = base_temp - 2 + np.random.randn(12) * 1.5\n\n# Create ColumnDataSources\nsource_a = ColumnDataSource(data={\"x\": months, \"y\": station_a})\nsource_b = ColumnDataSource(data={\"x\": months, \"y\": station_b})\nsource_c = ColumnDataSource(data={\"x\": months, \"y\": station_c})\n\n# Create figure\np = figure(\n    width=4800,\n    height=2700,\n    title=\"line-markers · bokeh · anyplot.ai\",\n    x_axis_label=\"Month\",\n    y_axis_label=\"Temperature (°C)\",\n)\n\n# Okabe-Ito color palette\ncolor_a = \"#009E73\"  # Okabe-Ito position 1 (bluish green)\ncolor_b = \"#C475FD\"  # Okabe-Ito position 2 (vermillion)\ncolor_c = \"#4467A3\"  # Okabe-Ito position 3 (blue)\n\n# Plot lines with markers - Station A (circles)\nline_a = p.line(\"x\", \"y\", source=source_a, line_width=4, color=color_a, alpha=0.85)\nscatter_a = p.scatter(\"x\", \"y\", source=source_a, size=18, color=color_a, marker=\"circle\", alpha=0.85)\n\n# Station B (squares)\nline_b = p.line(\"x\", \"y\", source=source_b, line_width=4, color=color_b, alpha=0.85)\nscatter_b = p.scatter(\"x\", \"y\", source=source_b, size=18, color=color_b, marker=\"square\", alpha=0.85)\n\n# Station C (triangles)\nline_c = p.line(\"x\", \"y\", source=source_c, line_width=4, color=color_c, alpha=0.85)\nscatter_c = p.scatter(\"x\", \"y\", source=source_c, size=18, color=color_c, marker=\"triangle\", alpha=0.85)\n\n# Legend with improved sizing\nlegend = Legend(\n    items=[(\"Station A\", [line_a, scatter_a]), (\"Station B\", [line_b, scatter_b]), (\"Station C\", [line_c, scatter_c])],\n    location=\"top_left\",\n)\n\np.add_layout(legend)\np.legend.label_text_font_size = \"22pt\"\np.legend.glyph_height = 35\np.legend.glyph_width = 35\np.legend.spacing = 12\np.legend.padding = 20\np.legend.background_fill_color = ELEVATED_BG\np.legend.border_line_color = INK_SOFT\np.legend.label_text_color = INK_SOFT\np.legend.background_fill_alpha = 1.0\n\n# Style text for 4800x2700 canvas\np.title.text_font_size = \"28pt\"\np.title.text_color = INK\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\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# Custom x-axis tick labels for months\np.xaxis.ticker = months\np.xaxis.major_label_overrides = dict(zip(months, month_labels, strict=True))\n\n# Theme-adaptive styling\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\n\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# Write the interactive 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"}