{"spec_id":"waffle-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nwaffle-basic: Basic Waffle Chart\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-05\n\"\"\"\n\nimport os\n\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\nimport numpy as np\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# Okabe-Ito palette (canonical order)\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data - Survey responses (sums to 100%)\ncategories = [\"Strongly Agree\", \"Agree\", \"Neutral\", \"Disagree\"]\nvalues = [48, 32, 15, 5]\n\n# Create 10x10 grid (100 squares, each = 1%)\ngrid_size = 10\ntotal_squares = grid_size * grid_size\n\n# Build grid data - fill squares by category\ngrid = np.zeros(total_squares, dtype=int)\nstart_idx = 0\nfor i, val in enumerate(values):\n    grid[start_idx : start_idx + val] = i\n    start_idx += val\n\n# Reshape to 10x10 grid\ngrid = grid.reshape((grid_size, grid_size))\n\n# Create plot (4800x2700 px)\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Draw squares\nsquare_size = 0.9  # Slightly smaller than 1 for gaps\nfor row in range(grid_size):\n    for col in range(grid_size):\n        category_idx = grid[row, col]\n        rect = mpatches.FancyBboxPatch(\n            (col + 0.05, row + 0.05),\n            square_size,\n            square_size,\n            boxstyle=\"round,pad=0.02,rounding_size=0.1\",\n            facecolor=IMPRINT[category_idx],\n            edgecolor=PAGE_BG,\n            linewidth=1.5,\n        )\n        ax.add_patch(rect)\n\n# Set axis limits and remove axes\nax.set_xlim(0, grid_size)\nax.set_ylim(0, grid_size)\nax.set_aspect(\"equal\")\nax.axis(\"off\")\n\n# Create legend with percentage labels\nlegend_patches = [\n    mpatches.Patch(color=IMPRINT[i], label=f\"{categories[i]} ({values[i]}%)\") for i in range(len(categories))\n]\nleg = ax.legend(\n    handles=legend_patches, loc=\"center left\", bbox_to_anchor=(1.02, 0.5), fontsize=18, frameon=True, fancybox=True\n)\nif leg:\n    leg.get_frame().set_facecolor(ELEVATED_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    leg.get_frame().set_linewidth(0.8)\n    plt.setp(leg.get_texts(), color=INK_SOFT)\n\n# Title and subtitle\nax.text(\n    0.5,\n    1.08,\n    \"waffle-basic · matplotlib · anyplot.ai\",\n    transform=ax.transAxes,\n    fontsize=24,\n    fontweight=\"medium\",\n    color=INK,\n    ha=\"center\",\n)\nax.text(0.5, 1.02, \"Survey Response Distribution\", transform=ax.transAxes, fontsize=16, color=INK_SOFT, ha=\"center\")\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}