{"spec_id":"scatter-basic","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nscatter-basic: Basic Scatter Plot\nLibrary: letsplot 4.10.1 | Python 3.13.14\nQuality: 92/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_point,\n    geom_smooth,\n    ggplot,\n    ggsize,\n    labs,\n    layer_tooltips,\n    theme,\n    theme_minimal,\n)\nfrom lets_plot.export import ggsave\n\n\nLetsPlot.setup_html()\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\"\n# Pre-blended ~10% INK over PAGE_BG (element_line has no alpha in lets-plot)\nGRID = \"#E4E2DB\" if THEME == \"light\" else \"#2F2F2C\"\nBRAND = \"#009E73\"  # Imprint palette position 1\n\n# Data — study hours vs exam scores (moderate positive correlation ~0.7)\nnp.random.seed(42)\nstudy_hours = np.random.uniform(1.0, 10.0, 180)\nexam_scores = study_hours * 6.8 + np.random.normal(0, 7.5, 180) + 28\nexam_scores = np.clip(exam_scores, 30, 105)\ndf = pd.DataFrame({\"study_hours\": study_hours, \"exam_scores\": exam_scores})\n\n# Plot — linear trend beneath points guides the eye to the correlation\nplot = (\n    ggplot(df, aes(x=\"study_hours\", y=\"exam_scores\"))\n    + geom_smooth(method=\"lm\", se=True, color=INK_SOFT, fill=INK_SOFT, alpha=0.12, size=1.0)\n    + geom_point(\n        shape=21,\n        fill=BRAND,\n        color=PAGE_BG,\n        size=2.5,\n        alpha=0.75,\n        stroke=0.8,\n        tooltips=layer_tooltips().line(\"Study Hours: @study_hours h\").line(\"Exam Score: @exam_scores pts\"),\n    )\n    + labs(\n        x=\"Study Hours per Day\",\n        y=\"Exam Score (points)\",\n        title=\"scatter-basic · python · letsplot · anyplot.ai\",\n        subtitle=\"Moderate positive correlation — more study time, higher scores\",\n    )\n    + ggsize(800, 450)\n    + theme_minimal()\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_grid_major=element_line(color=GRID, size=0.4),\n        panel_grid_minor=element_blank(),\n        axis_title=element_text(size=12, color=INK),\n        axis_text=element_text(size=10, color=INK_SOFT),\n        axis_line=element_line(color=INK_SOFT, size=0.4),\n        axis_ticks=element_blank(),\n        plot_title=element_text(size=16, color=INK, face=\"bold\"),\n        plot_subtitle=element_text(size=12, color=INK_SOFT),\n    )\n)\n\n# Save — ggsize(800, 450) × scale=4 → 3200 × 1800 px\nggsave(plot, filename=f\"plot-{THEME}.png\", path=\".\", scale=4)\nggsave(plot, filename=f\"plot-{THEME}.html\", path=\".\")\n"}