{"spec_id":"scatter-annotated","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nscatter-annotated: Annotated Scatter Plot with Text Labels\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 72/100 | Updated: 2026-05-13\n\"\"\"\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    element_text,\n    geom_point,\n    geom_text,\n    ggplot,\n    labs,\n    scale_x_continuous,\n    scale_y_continuous,\n    theme,\n    theme_minimal,\n)\n\n\n# Data - Company performance metrics (fewer points to avoid label overlap)\nnp.random.seed(42)\n\ncompanies = [\n    \"TechCorp\",\n    \"DataFlow\",\n    \"CloudNet\",\n    \"AI Labs\",\n    \"InfoSys\",\n    \"AppWorks\",\n    \"SoftCore\",\n    \"CodeBase\",\n    \"SmartSys\",\n    \"WebDev\",\n]\n\n# Revenue (millions) and Profit Margin (percentage) - spread out to avoid overlap\nrevenue = np.array([35, 95, 140, 200, 65, 170, 110, 55, 125, 80])\nprofit_margin = np.array([6, 12, 18, 23, 9, 20, 15, 8, 16, 11])\n\n# Add small variation\nrevenue = revenue + np.random.uniform(-3, 3, len(companies))\nprofit_margin = profit_margin + np.random.uniform(-0.5, 0.5, len(companies))\n\ndf = pd.DataFrame({\"company\": companies, \"revenue\": revenue, \"profit_margin\": profit_margin})\n\n# Create plot\nplot = (\n    ggplot(df, aes(x=\"revenue\", y=\"profit_margin\"))\n    + geom_point(size=6, alpha=0.7, color=\"#306998\")\n    + geom_text(aes(label=\"company\"), size=11, nudge_y=0.9, color=\"#333333\", va=\"bottom\")\n    + labs(x=\"Annual Revenue ($ Millions)\", y=\"Profit Margin (%)\", title=\"scatter-annotated · plotnine · pyplots.ai\")\n    + scale_x_continuous(limits=(20, 220))\n    + scale_y_continuous(limits=(4, 26))\n    + theme_minimal()\n    + theme(\n        figure_size=(16, 9),\n        text=element_text(size=14),\n        axis_title=element_text(size=20),\n        axis_text=element_text(size=16),\n        plot_title=element_text(size=24),\n    )\n)\n\n# Save\nplot.save(\"plot.png\", dpi=300, verbose=False)\n"}