{"spec_id":"scatter-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nscatter-basic: Basic Scatter Plot\nLibrary: plotnine 0.15.7 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    coord_cartesian,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_point,\n    geom_smooth,\n    ggplot,\n    labs,\n    scale_x_continuous,\n    scale_y_continuous,\n    theme,\n    theme_minimal,\n)\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\"\nGRID = INK\nBRAND = \"#009E73\"  # Imprint palette position 1 — always first series\n\n# Data\nnp.random.seed(42)\nn_points = 220\nstudy_hours = np.random.uniform(1, 10, n_points)\nexam_scores = np.clip(32 + study_hours * 6 + np.random.randn(n_points) * 7, 15, 100)\ndf = pd.DataFrame({\"study_hours\": study_hours, \"exam_scores\": exam_scores})\n\n# Plot\ntitle = \"scatter-basic · python · plotnine · anyplot.ai\"\nplot = (\n    ggplot(df, aes(x=\"study_hours\", y=\"exam_scores\"))\n    + geom_smooth(method=\"lm\", color=INK, fill=INK, alpha=0.08, size=1.2, se=True)\n    + geom_point(shape=\"o\", fill=BRAND, color=PAGE_BG, alpha=0.65, size=3.0, stroke=0.6)\n    + scale_x_continuous(breaks=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], expand=(0.02, 0.02))\n    + scale_y_continuous(breaks=[20, 30, 40, 50, 60, 70, 80, 90, 100], expand=(0.03, 0.03))\n    + coord_cartesian(xlim=(0.5, 10.5), ylim=(15, 100))\n    + labs(x=\"Study Hours (per week)\", y=\"Exam Score (points)\", title=title)\n    + theme_minimal()\n    + theme(\n        figure_size=(8, 4.5),\n        text=element_text(size=7, color=INK_SOFT),\n        plot_title=element_text(size=12, color=INK, ha=\"left\", margin={\"b\": 8}),\n        axis_title_x=element_text(size=10, color=INK, margin={\"t\": 8}),\n        axis_title_y=element_text(size=10, color=INK, margin={\"r\": 8}),\n        axis_text=element_text(size=8, color=INK_SOFT),\n        axis_ticks=element_blank(),\n        axis_line_x=element_line(color=INK_SOFT, size=0.6),\n        axis_line_y=element_blank(),\n        panel_grid_major_x=element_blank(),\n        panel_grid_major_y=element_line(color=GRID, size=0.4, alpha=0.15),\n        panel_grid_minor=element_blank(),\n        panel_border=element_blank(),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        plot_margin=0.03,\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}