{"spec_id":"scatter-text","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-text: Scatter Plot with Text Labels Instead of Points\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 93/100 | Updated: 2026-05-17\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.patches import Patch\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Okabe-Ito categorical palette\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data: Programming languages positioned by paradigm similarity\n# (simulating dimensionality reduction output)\nlanguages = [\n    \"Python\",\n    \"JavaScript\",\n    \"Java\",\n    \"C++\",\n    \"Ruby\",\n    \"Go\",\n    \"Rust\",\n    \"Swift\",\n    \"Kotlin\",\n    \"TypeScript\",\n    \"Scala\",\n    \"Haskell\",\n    \"Clojure\",\n    \"Elixir\",\n    \"Julia\",\n    \"R\",\n    \"MATLAB\",\n    \"Perl\",\n    \"PHP\",\n    \"C#\",\n    \"F#\",\n    \"OCaml\",\n    \"Erlang\",\n    \"Lua\",\n    \"Dart\",\n    \"Zig\",\n    \"Nim\",\n    \"Crystal\",\n    \"Groovy\",\n    \"Fortran\",\n]\n\n# Improved coordinates to reduce overlap while maintaining logical clusters\nx = np.array(\n    [\n        1.5,\n        3.2,\n        4.0,\n        5.8,\n        2.5,\n        6.2,\n        6.8,\n        5.0,\n        4.8,\n        3.5,\n        3.0,\n        0.5,\n        1.0,\n        0.8,\n        2.2,\n        1.2,\n        2.3,\n        3.5,\n        2.5,\n        4.2,\n        2.8,\n        0.3,\n        1.8,\n        4.5,\n        5.8,\n        6.5,\n        5.5,\n        3.2,\n        4.5,\n        7.0,\n    ]\n)\n\ny = np.array(\n    [\n        5.8,\n        4.8,\n        3.2,\n        2.0,\n        5.5,\n        3.5,\n        2.5,\n        3.8,\n        3.2,\n        4.3,\n        4.0,\n        6.8,\n        6.5,\n        5.8,\n        4.8,\n        4.2,\n        3.8,\n        3.2,\n        2.8,\n        3.0,\n        6.2,\n        6.2,\n        5.5,\n        2.5,\n        4.5,\n        1.8,\n        2.2,\n        5.8,\n        3.2,\n        1.2,\n    ]\n)\n\n# Category assignments\ncategories = [\n    \"dynamic\",\n    \"dynamic\",\n    \"jvm\",\n    \"systems\",\n    \"dynamic\",\n    \"systems\",\n    \"systems\",\n    \"systems\",\n    \"jvm\",\n    \"dynamic\",\n    \"jvm\",\n    \"functional\",\n    \"functional\",\n    \"functional\",\n    \"dynamic\",\n    \"dynamic\",\n    \"dynamic\",\n    \"dynamic\",\n    \"dynamic\",\n    \"jvm\",\n    \"functional\",\n    \"functional\",\n    \"functional\",\n    \"dynamic\",\n    \"dynamic\",\n    \"systems\",\n    \"systems\",\n    \"functional\",\n    \"jvm\",\n    \"systems\",\n]\n\ncategory_to_color = {\"dynamic\": IMPRINT[0], \"functional\": IMPRINT[1], \"systems\": IMPRINT[2], \"jvm\": IMPRINT[3]}\n\ncolor_list = [category_to_color[cat] for cat in categories]\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Plot text labels at each coordinate\nfor xi, yi, label, color in zip(x, y, languages, color_list, strict=True):\n    ax.text(\n        xi, yi, label, fontsize=18, ha=\"center\", va=\"center\", color=color, fontweight=\"bold\", alpha=0.9\n    )\n\n# Set axis limits with padding\nax.set_xlim(-0.5, 7.5)\nax.set_ylim(0.5, 7.5)\n\n# Labels and styling\nax.set_xlabel(\"Embedding Dimension 1\", fontsize=20, color=INK)\nax.set_ylabel(\"Embedding Dimension 2\", fontsize=20, color=INK)\nax.set_title(\"scatter-text · Python · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Grid\nax.grid(True, alpha=0.1, linewidth=0.8, color=INK)\n\n# Legend\nlegend_elements = [\n    Patch(facecolor=IMPRINT[0], label=\"Dynamic/Scripting\"),\n    Patch(facecolor=IMPRINT[1], label=\"Functional\"),\n    Patch(facecolor=IMPRINT[2], label=\"Systems\"),\n    Patch(facecolor=IMPRINT[3], label=\"JVM-based\"),\n]\nleg = ax.legend(handles=legend_elements, loc=\"upper right\", fontsize=16, framealpha=0.9)\nif leg:\n    leg.get_frame().set_facecolor(PAGE_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    for text in leg.get_texts():\n        text.set_color(INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}