{"spec_id":"dot-matrix-proportional","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ndot-matrix-proportional: Dot Matrix Chart for Proportional Counts\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 89/100 | Created: 2026-05-08\n\"\"\"\n\nimport os\n\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\n# Data: remote work preference survey, n=100 employees\ncategories = [\"Hybrid\", \"Fully Remote\", \"In-Office\"]\ncounts = [44, 35, 21]\ntotal = sum(counts)  # 100\n\n# Grid: 10 columns × 10 rows\nn_cols = 10\nn_rows = total // n_cols\n\n# Assign category index to each dot (left-to-right, top-to-bottom)\ndot_cats = []\nfor i, c in enumerate(counts):\n    dot_cats.extend([i] * c)\n\nxs = [idx % n_cols for idx in range(total)]\nys = [n_rows - 1 - idx // n_cols for idx in range(total)]\ndot_colors = [IMPRINT[c] for c in dot_cats]\n\n# Landscape figure: dot grid occupies a square central column; legend sits below\nfig, ax = plt.subplots(figsize=(16, 10), facecolor=PAGE_BG)\n# Axes spans roughly 7 × 7 inches in the center of a 16 × 10 figure.\n# With 10.3 data units in both x and y this gives ~204 px/unit @ 300 dpi,\n# so s ≈ 1000 yields ~65 % fill diameter.\nfig.subplots_adjust(left=0.265, right=0.735, top=0.88, bottom=0.17)\nax.set_facecolor(PAGE_BG)\n\nax.scatter(xs, ys, c=dot_colors, s=1000, edgecolors=PAGE_BG, linewidth=1.8, zorder=2)\n\nax.set_xlim(-0.65, n_cols - 0.35)\nax.set_ylim(-0.65, n_rows - 0.35)\nax.axis(\"off\")\n\n# Legend — three items in one row, centred below the grid\nhandles = [\n    mpatches.Patch(color=IMPRINT[i], label=f\"{categories[i]}  —  {counts[i]} / {total}\")\n    for i in range(len(categories))\n]\nleg = ax.legend(\n    handles=handles,\n    loc=\"upper center\",\n    bbox_to_anchor=(0.5, -0.05),\n    ncol=3,\n    fontsize=20,\n    frameon=True,\n    handlelength=1.8,\n    handleheight=1.4,\n    borderpad=0.8,\n    columnspacing=1.2,\n)\nleg.get_frame().set_facecolor(ELEVATED_BG)\nleg.get_frame().set_edgecolor(INK_SOFT)\nplt.setp(leg.get_texts(), color=INK_SOFT)\n\nax.set_title(\n    \"Remote Work Survey  ·  dot-matrix-proportional  ·  matplotlib  ·  anyplot.ai\",\n    fontsize=24,\n    fontweight=\"medium\",\n    color=INK,\n    pad=18,\n)\n\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}