{"spec_id":"chessboard-basic","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nchessboard-basic: Chess Board Grid Visualization\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-05-17\n\"\"\"\n\nimport os\nimport time\nfrom pathlib import Path\n\nfrom bokeh.io import output_file, save\nfrom bokeh.models import ColumnDataSource\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# Chess board colors (light and dark squares)\nLIGHT_SQUARE = \"#F0D9B5\"\nDARK_SQUARE = \"#B58863\"\n\n# Data - 8x8 chess board squares\ncolumns = list(\"abcdefgh\")\nrows = list(\"12345678\")\n\nx_coords = []\ny_coords = []\ncolors = []\n\nfor row_idx, _row in enumerate(rows):\n    for col_idx, _col in enumerate(columns):\n        x_coords.append(col_idx + 0.5)\n        y_coords.append(row_idx + 0.5)\n        if (row_idx + col_idx) % 2 == 0:\n            colors.append(DARK_SQUARE)\n        else:\n            colors.append(LIGHT_SQUARE)\n\nsource = ColumnDataSource(data={\"x\": x_coords, \"y\": y_coords, \"color\": colors})\n\n# Plot\np = figure(\n    width=3600,\n    height=3600,\n    title=\"chessboard-basic · bokeh · anyplot.ai\",\n    x_range=(-0.1, 8.1),\n    y_range=(-0.1, 8.1),\n    tools=\"\",\n    toolbar_location=None,\n)\n\np.rect(x=\"x\", y=\"y\", width=1, height=1, source=source, color=\"color\", line_color=INK_SOFT, line_width=2)\n\n# Style\np.title.text_font_size = \"32pt\"\np.title.text_color = INK\np.title.align = \"center\"\n\np.xaxis.ticker = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]\np.xaxis.major_label_overrides = {0.5: \"a\", 1.5: \"b\", 2.5: \"c\", 3.5: \"d\", 4.5: \"e\", 5.5: \"f\", 6.5: \"g\", 7.5: \"h\"}\np.xaxis.major_label_text_font_size = \"24pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.xaxis.axis_label = \"Column\"\np.xaxis.axis_label_text_font_size = \"22pt\"\np.xaxis.axis_label_text_color = INK\np.xaxis.axis_line_color = INK_SOFT\n\np.yaxis.ticker = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]\np.yaxis.major_label_overrides = {0.5: \"1\", 1.5: \"2\", 2.5: \"3\", 3.5: \"4\", 4.5: \"5\", 5.5: \"6\", 6.5: \"7\", 7.5: \"8\"}\np.yaxis.major_label_text_font_size = \"24pt\"\np.yaxis.major_label_text_color = INK_SOFT\np.yaxis.axis_label = \"Row\"\np.yaxis.axis_label_text_font_size = \"22pt\"\np.yaxis.axis_label_text_color = INK\np.yaxis.axis_line_color = INK_SOFT\n\np.xgrid.visible = False\np.ygrid.visible = False\n\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\np.outline_line_width = 3\n\n# Save HTML\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with headless Chrome\nW, H = 3600, 3600\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"}