{"spec_id":"sudoku-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nsudoku-basic: Basic Sudoku Grid\nLibrary: plotly 6.8.0 | Python 3.13.14\nQuality: 92/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\nimport sys\n\n\n# Remove script's own directory from sys.path so 'plotly.py' doesn't shadow the plotly package\nsys.path.pop(0)\n\nimport plotly.graph_objects as go\n\n\n# Theme tokens (Imprint palette chrome)\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 - A partially filled Sudoku puzzle (0 = empty cell)\ngrid = [\n    [5, 3, 0, 0, 7, 0, 0, 0, 0],\n    [6, 0, 0, 1, 9, 5, 0, 0, 0],\n    [0, 9, 8, 0, 0, 0, 0, 6, 0],\n    [8, 0, 0, 0, 6, 0, 0, 0, 3],\n    [4, 0, 0, 8, 0, 3, 0, 0, 1],\n    [7, 0, 0, 0, 2, 0, 0, 0, 6],\n    [0, 6, 0, 0, 0, 0, 2, 8, 0],\n    [0, 0, 0, 4, 1, 9, 0, 0, 5],\n    [0, 0, 0, 0, 8, 0, 0, 7, 9],\n]\n\nfig = go.Figure()\n\nshapes = []\n\n# Center box (rows 3-5, cols 3-5) focal point — ELEVATED_BG on all cells creates a visual anchor\nfor row in range(3, 6):\n    for col in range(3, 6):\n        if grid[row][col] == 0:\n            shapes.append(\n                {\n                    \"type\": \"rect\",\n                    \"x0\": col,\n                    \"x1\": col + 1,\n                    \"y0\": 8 - row,\n                    \"y1\": 9 - row,\n                    \"fillcolor\": ELEVATED_BG,\n                    \"line\": {\"width\": 0},\n                    \"layer\": \"below\",\n                }\n            )\n\n# Given-number cell fills — ELEVATED_BG background (below traces)\nfor row in range(9):\n    for col in range(9):\n        if grid[row][col] != 0:\n            shapes.append(\n                {\n                    \"type\": \"rect\",\n                    \"x0\": col,\n                    \"x1\": col + 1,\n                    \"y0\": 8 - row,\n                    \"y1\": 9 - row,\n                    \"fillcolor\": ELEVATED_BG,\n                    \"line\": {\"width\": 0},\n                    \"layer\": \"below\",\n                }\n            )\n\n# Given-number cell accent borders (above traces) — clearly distinguishes givens from empty cells\nfor row in range(9):\n    for col in range(9):\n        if grid[row][col] != 0:\n            shapes.append(\n                {\n                    \"type\": \"rect\",\n                    \"x0\": col,\n                    \"x1\": col + 1,\n                    \"y0\": 8 - row,\n                    \"y1\": 9 - row,\n                    \"fillcolor\": \"rgba(0,0,0,0)\",\n                    \"line\": {\"color\": INK_SOFT, \"width\": 1},\n                    \"layer\": \"above\",\n                }\n            )\n\n# Thick box boundaries via shapes API — rect shapes give clean corner joins (9 boxes)\nfor box_row in range(3):\n    for box_col in range(3):\n        shapes.append(\n            {\n                \"type\": \"rect\",\n                \"x0\": box_col * 3,\n                \"x1\": (box_col + 1) * 3,\n                \"y0\": box_row * 3,\n                \"y1\": (box_row + 1) * 3,\n                \"fillcolor\": \"rgba(0,0,0,0)\",\n                \"line\": {\"color\": INK, \"width\": 5},\n                \"layer\": \"above\",\n            }\n        )\n\n# Cell numbers as annotations (36px × scale=4 → 144px rendered — fills cell nicely)\nannotations = []\nfor row in range(9):\n    for col in range(9):\n        value = grid[row][col]\n        if value != 0:\n            annotations.append(\n                {\n                    \"x\": col + 0.5,\n                    \"y\": 8 - row + 0.5,\n                    \"text\": str(value),\n                    \"font\": {\"size\": 36, \"color\": INK, \"family\": \"Arial Black\"},\n                    \"showarrow\": False,\n                    \"xanchor\": \"center\",\n                    \"yanchor\": \"middle\",\n                }\n            )\n\n# Thin lines for individual cell boundaries (skip multiples of 3 — those are box lines)\nthin_lines_x = []\nthin_lines_y = []\nfor i in range(10):\n    if i % 3 != 0:\n        thin_lines_x.extend([i, i, None, 0, 9, None])\n        thin_lines_y.extend([0, 9, None, i, i, None])\n\nfig.add_trace(\n    go.Scatter(\n        x=thin_lines_x,\n        y=thin_lines_y,\n        mode=\"lines\",\n        line={\"color\": INK, \"width\": 1.5},\n        hoverinfo=\"skip\",\n        showlegend=False,\n    )\n)\n\n# Invisible hover layer — includes box number for richer cell context in HTML\nhover_x = [c + 0.5 for r in range(9) for c in range(9)]\nhover_y = [8 - r + 0.5 for r in range(9) for c in range(9)]\nhover_text = [\n    f\"Box {(r // 3) * 3 + (c // 3) + 1}, R{r + 1}C{c + 1}\" + (f\" = {grid[r][c]}\" if grid[r][c] != 0 else \" (empty)\")\n    for r in range(9)\n    for c in range(9)\n]\nfig.add_trace(\n    go.Scatter(\n        x=hover_x,\n        y=hover_y,\n        mode=\"markers\",\n        marker={\"size\": 50, \"color\": \"rgba(0,0,0,0)\"},\n        hovertext=hover_text,\n        hoverinfo=\"text\",\n        showlegend=False,\n    )\n)\n\n# Layout — square canvas (2400×2400) matches the symmetric 9×9 grid\nfig.update_layout(\n    autosize=False,\n    title={\n        \"text\": \"sudoku-basic · python · plotly · anyplot.ai\",\n        \"font\": {\"size\": 16, \"color\": INK},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n    },\n    xaxis={\n        \"showgrid\": False,\n        \"zeroline\": False,\n        \"showticklabels\": False,\n        \"range\": [-0.2, 9.2],\n        \"scaleanchor\": \"y\",\n        \"scaleratio\": 1,\n        \"fixedrange\": True,\n    },\n    yaxis={\"showgrid\": False, \"zeroline\": False, \"showticklabels\": False, \"range\": [-0.2, 9.2], \"fixedrange\": True},\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK_SOFT},\n    annotations=annotations,\n    shapes=shapes,\n    margin={\"l\": 60, \"r\": 60, \"t\": 80, \"b\": 60},\n)\n\n# Save — square 2400×2400 (width=600, height=600, scale=4)\nfig.write_image(f\"plot-{THEME}.png\", width=600, height=600, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}