{"spec_id":"map-tilegrid","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nmap-tilegrid: Tile Grid Map for Equal-Area Geographic Comparison\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 86/100 | Created: 2026-05-14\n\"\"\"\n\nimport os\nimport sys\n\n\nsys.path.insert(0, \"/home/runner/work/anyplot/anyplot/.venv/lib/python3.13/site-packages\")\n\nimport matplotlib.colors as mcolors\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\n\n\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\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.10,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# US state tile grid positions: (row, col), row 0 = top\nstate_grid = {\n    \"ME\": (0, 9),\n    \"VT\": (1, 9),\n    \"NH\": (1, 10),\n    \"WA\": (2, 0),\n    \"ID\": (2, 1),\n    \"MT\": (2, 2),\n    \"ND\": (2, 3),\n    \"MN\": (2, 4),\n    \"WI\": (2, 5),\n    \"MI\": (2, 7),\n    \"NY\": (2, 8),\n    \"MA\": (2, 9),\n    \"RI\": (2, 10),\n    \"OR\": (3, 0),\n    \"WY\": (3, 1),\n    \"SD\": (3, 2),\n    \"IA\": (3, 3),\n    \"IL\": (3, 4),\n    \"IN\": (3, 5),\n    \"OH\": (3, 6),\n    \"PA\": (3, 7),\n    \"NJ\": (3, 8),\n    \"CT\": (3, 9),\n    \"NV\": (4, 0),\n    \"UT\": (4, 1),\n    \"CO\": (4, 2),\n    \"NE\": (4, 3),\n    \"MO\": (4, 4),\n    \"KY\": (4, 5),\n    \"WV\": (4, 6),\n    \"VA\": (4, 7),\n    \"MD\": (4, 8),\n    \"DE\": (4, 9),\n    \"CA\": (5, 0),\n    \"AZ\": (5, 1),\n    \"NM\": (5, 2),\n    \"KS\": (5, 3),\n    \"TN\": (5, 4),\n    \"NC\": (5, 5),\n    \"SC\": (5, 7),\n    \"OK\": (6, 2),\n    \"AR\": (6, 3),\n    \"MS\": (6, 4),\n    \"AL\": (6, 5),\n    \"GA\": (6, 6),\n    \"TX\": (7, 2),\n    \"LA\": (7, 4),\n    \"FL\": (7, 7),\n    \"AK\": (8, 0),\n    \"HI\": (8, 1),\n}\n\n# Renewable energy adoption (%) — structured synthetic data by US state\nregional_base = {\n    \"WA\": 74,\n    \"OR\": 66,\n    \"CA\": 58,\n    \"ID\": 54,\n    \"MT\": 48,\n    \"WY\": 28,\n    \"NV\": 36,\n    \"UT\": 30,\n    \"CO\": 42,\n    \"AZ\": 38,\n    \"NM\": 37,\n    \"ND\": 44,\n    \"SD\": 50,\n    \"NE\": 36,\n    \"KS\": 40,\n    \"MN\": 33,\n    \"IA\": 40,\n    \"MO\": 23,\n    \"IL\": 21,\n    \"WI\": 26,\n    \"MI\": 24,\n    \"IN\": 19,\n    \"OH\": 20,\n    \"WV\": 17,\n    \"KY\": 21,\n    \"TN\": 24,\n    \"NC\": 33,\n    \"SC\": 28,\n    \"GA\": 30,\n    \"AL\": 22,\n    \"MS\": 21,\n    \"FL\": 28,\n    \"TX\": 33,\n    \"LA\": 19,\n    \"AR\": 26,\n    \"OK\": 36,\n    \"NY\": 30,\n    \"PA\": 23,\n    \"NJ\": 27,\n    \"CT\": 28,\n    \"MA\": 30,\n    \"VT\": 53,\n    \"NH\": 40,\n    \"ME\": 56,\n    \"MD\": 28,\n    \"DE\": 26,\n    \"VA\": 26,\n    \"RI\": 18,\n    \"HI\": 45,\n    \"AK\": 32,\n}\n\nnp.random.seed(42)\nstates = list(state_grid.keys())\nvalues = {s: float(np.clip(regional_base.get(s, 30) + np.random.normal(0, 2), 10, 80)) for s in states}\n\n# Plot\nMAX_ROW = 8\nTILE = 0.86\n\nfig = plt.figure(figsize=(12, 12), facecolor=PAGE_BG)\nax = fig.add_axes([0.04, 0.12, 0.92, 0.78])\nax.set_facecolor(PAGE_BG)\n\ncmap = plt.colormaps[\"viridis\"]\nnorm = mcolors.Normalize(vmin=10, vmax=80)\n\nfor state, (gr, gc) in state_grid.items():\n    y = MAX_ROW - gr\n    rgba = cmap(norm(values[state]))\n    luma = 0.299 * rgba[0] + 0.587 * rgba[1] + 0.114 * rgba[2]\n\n    offset = (1 - TILE) / 2\n    ax.add_patch(\n        mpatches.Rectangle(\n            (gc + offset, y + offset), TILE, TILE, facecolor=rgba, edgecolor=PAGE_BG, linewidth=2.5, zorder=2\n        )\n    )\n    ax.text(\n        gc + 0.5,\n        y + 0.5,\n        state,\n        ha=\"center\",\n        va=\"center\",\n        fontsize=15,\n        fontweight=\"bold\",\n        color=\"#1A1A17\" if luma > 0.40 else \"#F0EFE8\",\n        zorder=3,\n    )\n\nax.set_xlim(-0.2, 11.2)\nax.set_ylim(-0.8, 9.5)\nax.set_aspect(\"equal\")\nax.axis(\"off\")\nax.set_title(\n    \"Renewable Energy by State · map-tilegrid · seaborn · anyplot.ai\",\n    fontsize=22,\n    fontweight=\"medium\",\n    color=INK,\n    pad=16,\n)\n\n# Colorbar\ncax = fig.add_axes([0.15, 0.05, 0.70, 0.026])\nsm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)\nsm.set_array([])\ncbar = fig.colorbar(sm, cax=cax, orientation=\"horizontal\")\ncbar.set_label(\"Renewable Energy Adoption (%)\", fontsize=20, color=INK, labelpad=10)\ncbar.ax.tick_params(labelsize=16, colors=INK_SOFT)\ncbar.outline.set_edgecolor(INK_SOFT)\n\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}