{"spec_id":"scatter-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-basic: Basic Scatter Plot\nLibrary: matplotlib 3.11.0 | Python 3.13.14\nQuality: 91/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport matplotlib as mpl\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\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"  # Imprint palette position 1 — ALWAYS first series\n\nmpl.rcParams.update(\n    {\"font.family\": \"DejaVu Sans\", \"axes.titlepad\": 18, \"axes.labelpad\": 12, \"axes.unicode_minus\": True}\n)\n\n# Data — study hours vs exam scores (r ~ 0.7)\nnp.random.seed(42)\nstudy_hours = np.random.uniform(1, 12, 180)\nexam_scores = np.clip(38 + study_hours * 4.5 + np.random.normal(0, 12, 180), 35, 100)\n\n# Title\ntitle = \"scatter-basic · python · matplotlib · anyplot.ai\"\nn = len(title)\ntitle_fontsize = max(8, round(12 * 67 / n)) if n > 67 else 12\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nax.scatter(study_hours, exam_scores, s=130, alpha=0.65, color=BRAND, edgecolors=PAGE_BG, linewidths=0.6, zorder=3)\n\n# Trend line + 95% confidence band — showcase fill_between analytical capability\ncoeffs = np.polyfit(study_hours, exam_scores, 1)\nx_line = np.linspace(study_hours.min(), study_hours.max(), 200)\ny_line = np.polyval(coeffs, x_line)\n\nn_pts = len(study_hours)\nx_mean = np.mean(study_hours)\nSxx = np.sum((study_hours - x_mean) ** 2)\ns_res = np.sqrt(np.sum((exam_scores - np.polyval(coeffs, study_hours)) ** 2) / (n_pts - 2))\nse_band = s_res * np.sqrt(1 / n_pts + (x_line - x_mean) ** 2 / Sxx)\nax.fill_between(x_line, y_line - 1.96 * se_band, y_line + 1.96 * se_band, color=INK_SOFT, alpha=0.12, zorder=0)\nax.plot(x_line, y_line, color=INK_SOFT, linewidth=2.2, alpha=0.75, zorder=1)\n\n# Style\nax.set_xlabel(\"Study Hours per Week\", fontsize=10, color=INK)\nax.set_ylabel(\"Exam Score (%)\", fontsize=10, color=INK)\nax.set_title(title, fontsize=title_fontsize, fontweight=\"medium\", color=INK)\n\nax.tick_params(axis=\"both\", which=\"both\", labelsize=8, colors=INK_SOFT, length=0, pad=8)\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor spine in (\"left\", \"bottom\"):\n    ax.spines[spine].set_color(INK_SOFT)\n    ax.spines[spine].set_linewidth(0.8)\n\nax.yaxis.grid(True, alpha=0.12, linewidth=0.6, color=INK)\nax.set_axisbelow(True)\nax.margins(x=0.04, y=0.08)\n\n# Pearson r footnote\nr = np.corrcoef(study_hours, exam_scores)[0, 1]\nfig.text(\n    0.985, 0.03, f\"n = {len(study_hours)}  ·  Pearson r = {r:.2f}\", fontsize=8, color=INK_MUTED, ha=\"right\", va=\"bottom\"\n)\n\nfig.subplots_adjust(left=0.09, right=0.97, top=0.90, bottom=0.14)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}