{"spec_id":"scatter-annotated","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-annotated: Annotated Scatter Plot with Text Labels\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-13\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\"\nBRAND = \"#009E73\"\n\n# Data - Technology companies with market cap and revenue\ncompanies = [\n    \"TechCorp\",\n    \"DataSys\",\n    \"CloudNet\",\n    \"ByteWorks\",\n    \"QuantumAI\",\n    \"NexGen\",\n    \"CyberFlow\",\n    \"InfoPrime\",\n    \"CodeLabs\",\n    \"DigiCore\",\n    \"NetSphere\",\n    \"AlgoTech\",\n    \"VisionX\",\n    \"PulseTech\",\n    \"ZetaLogic\",\n]\nmarket_cap = np.array([55, 135, 105, 18, 225, 70, 120, 45, 165, 85, 30, 195, 150, 175, 60])\nrevenue = np.array([12, 42, 30, 4, 65, 18, 38, 10, 52, 24, 6, 58, 45, 50, 15])\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nax.scatter(market_cap, revenue, s=250, alpha=0.7, color=BRAND, edgecolors=PAGE_BG, linewidths=2, zorder=3)\n\n# Custom annotation offsets to avoid overlap\noffsets = [\n    (10, -10),\n    (-10, 8),\n    (10, 8),\n    (-10, -12),\n    (10, 8),\n    (-10, 8),\n    (10, -10),\n    (10, -10),\n    (-12, 8),\n    (10, 8),\n    (-10, -10),\n    (10, -12),\n    (10, 8),\n    (10, 10),\n    (-10, -10),\n]\n\n# Annotate each point\nfor i, company in enumerate(companies):\n    x_offset, y_offset = offsets[i]\n    ha = \"left\" if x_offset > 0 else \"right\"\n\n    ax.annotate(\n        company,\n        xy=(market_cap[i], revenue[i]),\n        xytext=(x_offset, y_offset),\n        textcoords=\"offset points\",\n        fontsize=13,\n        color=INK,\n        fontweight=\"medium\",\n        ha=ha,\n        va=\"center\",\n        arrowprops={\"arrowstyle\": \"-\", \"color\": INK_SOFT, \"lw\": 1, \"connectionstyle\": \"arc3,rad=0\"},\n        zorder=4,\n    )\n\n# Style\nax.set_xlabel(\"Market Capitalization ($ Billions)\", fontsize=20, color=INK)\nax.set_ylabel(\"Annual Revenue ($ Billions)\", fontsize=20, color=INK)\nax.set_title(\"scatter-annotated · matplotlib · anyplot.ai\", fontsize=24, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\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)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\nax.set_xlim(0, 240)\nax.set_ylim(0, 70)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}