{"spec_id":"scatter-categorical","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-categorical: Categorical Scatter Plot\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\n\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 = [\n    \"#009E73\",  # bluish green — ALWAYS first series\n    \"#C475FD\",  # vermillion\n    \"#4467A3\",  # blue\n    \"#BD8233\",  # reddish purple\n]\n\n# Data — plant species with distinct petal characteristics\nnp.random.seed(42)\nn_per_group = 40\n\n# Species A: Smaller petals\nspecies_a_x = np.random.normal(1.5, 0.3, n_per_group)\nspecies_a_y = np.random.normal(0.3, 0.1, n_per_group)\n\n# Species B: Medium petals\nspecies_b_x = np.random.normal(4.0, 0.5, n_per_group)\nspecies_b_y = np.random.normal(1.3, 0.2, n_per_group)\n\n# Species C: Larger petals\nspecies_c_x = np.random.normal(5.5, 0.6, n_per_group)\nspecies_c_y = np.random.normal(2.0, 0.3, n_per_group)\n\ncategories = [\"Species A\", \"Species B\", \"Species C\"]\nmarkers = [\"o\", \"s\", \"^\"]\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Plot each category with distinct colors and markers\nscatter_data = [\n    (species_a_x, species_a_y, IMPRINT[0], markers[0]),\n    (species_b_x, species_b_y, IMPRINT[1], markers[1]),\n    (species_c_x, species_c_y, IMPRINT[2], markers[2]),\n]\n\nfor i, (x, y, color, marker) in enumerate(scatter_data):\n    ax.scatter(x, y, s=200, c=color, alpha=0.8, label=categories[i], marker=marker, edgecolors=PAGE_BG, linewidth=0.5)\n\n# Labels and styling\nax.set_xlabel(\"Petal Length (cm)\", fontsize=20, color=INK)\nax.set_ylabel(\"Petal Width (cm)\", fontsize=20, color=INK)\nax.set_title(\"scatter-categorical · matplotlib · anyplot.ai\", fontsize=24, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\nfor spine in (\"left\", \"bottom\"):\n    ax.spines[spine].set_color(INK_SOFT)\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\n\nax.yaxis.grid(True, alpha=0.1, linewidth=0.8, color=INK)\n\n# Legend\nleg = ax.legend(fontsize=16, loc=\"upper left\")\nif leg:\n    leg.get_frame().set_facecolor(ELEVATED_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    plt.setp(leg.get_texts(), color=INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}