{"spec_id":"scatter-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nscatter-basic: Basic Scatter Plot\nLibrary: seaborn 0.13.2 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\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\"  # Imprint palette position 1\n\n# Data — marketing spend vs. quarterly sales revenue (r~0.75)\nnp.random.seed(42)\nn = 220\nmarketing_spend = np.random.gamma(shape=2.2, scale=9.0, size=n) + 3\nsales_revenue = 4.1 * marketing_spend + np.random.normal(0, 18, n) + 15\nsales_revenue = np.clip(sales_revenue, 5, None)\n\ndf = pd.DataFrame({\"Marketing Spend ($ thousands)\": marketing_spend, \"Quarterly Revenue ($ thousands)\": sales_revenue})\n\n# Plot\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n        \"axes.linewidth\": 0.9,\n        \"axes.grid\": True,\n        \"axes.axisbelow\": True,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# regplot adds regression line + 95% CI band — seaborn's distinctive statistical layer\nsns.regplot(\n    data=df,\n    x=\"Marketing Spend ($ thousands)\",\n    y=\"Quarterly Revenue ($ thousands)\",\n    ax=ax,\n    color=BRAND,\n    scatter_kws={\"s\": 72, \"alpha\": 0.55, \"edgecolors\": PAGE_BG},\n    line_kws={\"linewidth\": 2.0},\n    ci=95,\n)\n\n# Pearson r annotation surfaces the correlation insight\nr = np.corrcoef(marketing_spend, sales_revenue)[0, 1]\nax.annotate(f\"r = {r:.2f}\", xy=(0.97, 0.06), xycoords=\"axes fraction\", ha=\"right\", fontsize=8, color=INK_SOFT)\n\n# Style\nax.set_title(\"scatter-basic · python · seaborn · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=14)\nax.set_xlabel(\"Marketing Spend ($ thousands)\", fontsize=10, color=INK, labelpad=10)\nax.set_ylabel(\"Quarterly Revenue ($ thousands)\", fontsize=10, color=INK, labelpad=10)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT, length=0)\nax.margins(x=0.04, y=0.06)\nsns.despine(ax=ax)\n\nfig.subplots_adjust(left=0.11, right=0.97, top=0.93, bottom=0.13)\n\n# Save — no bbox_inches='tight' (would trim the 3200×1800 canvas)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}