{"spec_id":"scatter-categorical","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nscatter-categorical: Categorical Scatter Plot\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 88/100 | Created: 2026-05-12\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import *\nfrom lets_plot.export import ggsave as export_ggsave\n\n\nLetsPlot.setup_html()\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\"\n\n# Okabe-Ito palette\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data: Plant growth by treatment type\nnp.random.seed(42)\ntreatment_a = np.random.normal(loc=45, scale=8, size=40)\ngrowth_a = treatment_a * 1.1 + np.random.normal(loc=5, scale=6, size=40)\n\ntreatment_b = np.random.normal(loc=52, scale=9, size=35)\ngrowth_b = treatment_b * 0.95 + np.random.normal(loc=3, scale=7, size=35)\n\ntreatment_c = np.random.normal(loc=38, scale=7, size=38)\ngrowth_c = treatment_c * 1.25 + np.random.normal(loc=8, scale=5, size=38)\n\ntreatment_d = np.random.normal(loc=55, scale=10, size=37)\ngrowth_d = treatment_d * 0.85 + np.random.normal(loc=2, scale=8, size=37)\n\ndf = pd.DataFrame(\n    {\n        \"Temperature (°C)\": np.concatenate([treatment_a, treatment_b, treatment_c, treatment_d]),\n        \"Growth Rate (%)\": np.concatenate([growth_a, growth_b, growth_c, growth_d]),\n        \"Treatment\": ([\"Treatment A\"] * 40 + [\"Treatment B\"] * 35 + [\"Treatment C\"] * 38 + [\"Treatment D\"] * 37),\n    }\n)\n\n# Plot with shape variation for visual hierarchy and distinction\nplot = (\n    ggplot(df, aes(x=\"Temperature (°C)\", y=\"Growth Rate (%)\", color=\"Treatment\", shape=\"Treatment\"))\n    + geom_point(size=3.5, alpha=0.8, stroke=0.8)\n    + scale_color_manual(values=IMPRINT[:4])\n    + scale_shape_manual(values=[21, 22, 23, 24])  # Circle, square, diamond, triangle\n    + labs(\n        x=\"Temperature (°C)\",\n        y=\"Growth Rate (%)\",\n        title=\"scatter-categorical · letsplot · anyplot.ai\",\n        color=\"Treatment\",\n        shape=\"Treatment\",\n    )\n    + ggsize(1600, 900)\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=None),\n        panel_grid_major=element_line(color=INK_SOFT, size=0.15),\n        panel_grid_minor=element_blank(),\n        axis_title=element_text(size=20, color=INK, face=\"bold\"),\n        axis_text=element_text(size=16, color=INK_SOFT),\n        axis_line=element_line(color=INK_SOFT, size=0.5),\n        plot_title=element_text(size=24, color=INK, face=\"bold\"),\n        legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT, size=0.5),\n        legend_text=element_text(size=16, color=INK_SOFT),\n        legend_title=element_text(size=16, color=INK, face=\"bold\"),\n    )\n)\n\n# Save\nexport_ggsave(plot, filename=f\"plot-{THEME}.png\", path=\".\", scale=3)\nexport_ggsave(plot, filename=f\"plot-{THEME}.html\", path=\".\")\n"}