{"spec_id":"sudoku-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nsudoku-basic: Basic Sudoku Grid\nLibrary: seaborn 0.13.2 | Python 3.13.14\nQuality: 92/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\nfrom matplotlib.colors import ListedColormap\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# Extended tonal palette for alternating box shading (monochrome, warm-toned)\nBOX_SHADE = \"#EDE8DB\" if THEME == \"light\" else \"#242422\"  # alternate 3×3 box fill\nCLUE_BG = \"#DDD8CB\" if THEME == \"light\" else \"#2E2D29\"  # given-number cell fill\n\n# Data (classic Sudoku puzzle; 0 = empty cell)\ngrid = np.array(\n    [\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)\nclue_mask = (grid > 0).astype(float)\nannotations = np.where(grid == 0, \"\", grid.astype(str))\n\n# Three-level cell data: 0=empty+even-box, 0.5=empty+odd-box, 1=clue.\n# Alternating box parity encodes the checkerboard 3×3 grouping directly in the data.\nbox_parity = np.array([[(r // 3 + c // 3) % 2 * 0.5 for c in range(9)] for r in range(9)], dtype=float)\ncell_data = np.where(clue_mask == 1, 1.0, box_parity)\ncmap = ListedColormap([PAGE_BG, BOX_SHADE, CLUE_BG])\n\n# Theme-adaptive seaborn chrome (matches seaborn.md template)\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.15,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Canvas: square 2400×2400 (symmetric 9×9 grid — no preferred horizontal axis)\nfig, ax = plt.subplots(figsize=(6, 6), dpi=400, facecolor=PAGE_BG)\n\n# Seaborn heatmap: ListedColormap with 3 warm-toned stops maps directly to cell types.\n# Alternating box shading (even vs odd 3×3 boxes) reinforces the structural grouping\n# without coloring — preserving the monochrome constraint while lifting design quality.\nsns.heatmap(\n    cell_data,\n    annot=annotations,\n    fmt=\"\",\n    cmap=cmap,\n    cbar=False,\n    linewidths=0.6,\n    linecolor=INK_SOFT,\n    square=True,\n    xticklabels=False,\n    yticklabels=False,\n    vmin=0,\n    vmax=1,\n    annot_kws={\"size\": 16, \"weight\": \"bold\", \"color\": INK},\n    ax=ax,\n)\n\n# Thick 3×3 box boundaries at linewidth=3 vs thin 0.6 → sharp thick/thin hierarchy\nfor k in range(4):\n    ax.axhline(y=k * 3, color=INK, linewidth=3, clip_on=False)\n    ax.axvline(x=k * 3, color=INK, linewidth=3, clip_on=False)\n\nax.set_title(\"sudoku-basic · python · seaborn · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=16)\nax.set_xticks([])\nax.set_yticks([])\nax.set_xlim(0, 9)\nax.set_ylim(9, 0)\n\nplt.tight_layout()\n# bbox_inches must stay default (None) — 'tight' silently trims the canvas\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}