{"spec_id":"scatter-categorical","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nscatter-categorical: Categorical Scatter Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-12\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\"\n\n# Okabe-Ito palette - canonical order, first series always #009E73\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\n# Configure seaborn theme\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        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Data - IoT sensor readings across three sensor types\nnp.random.seed(42)\n\nn_per_group = 50\n\n# Temperature sensors: readings range 15-35°C, with humidity correlation\ntemp_x = np.random.normal(25, 4, n_per_group)\ntemp_y = np.random.normal(55, 10, n_per_group)\n\n# Pressure sensors: readings range 995-1015 hPa, with higher variance\npressure_x = np.random.normal(1005, 5, n_per_group)\npressure_y = np.random.normal(65, 12, n_per_group)\n\n# Humidity sensors: readings range 30-90%, with temperature correlation\nhumidity_x = np.random.normal(28, 4.5, n_per_group)\nhumidity_y = np.random.normal(72, 11, n_per_group)\n\ndf = pd.DataFrame(\n    {\n        \"Ambient Value\": np.concatenate([temp_x, pressure_x, humidity_x]),\n        \"Sensor Output\": np.concatenate([temp_y, pressure_y, humidity_y]),\n        \"Sensor Type\": [\"Temperature\"] * n_per_group + [\"Pressure\"] * n_per_group + [\"Humidity\"] * n_per_group,\n    }\n)\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\n\nsns.scatterplot(\n    data=df,\n    x=\"Ambient Value\",\n    y=\"Sensor Output\",\n    hue=\"Sensor Type\",\n    palette=IMPRINT,\n    s=200,\n    alpha=0.7,\n    edgecolor=PAGE_BG,\n    linewidth=0.5,\n    ax=ax,\n)\n\n# Styling\nax.set_title(\"scatter-categorical · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.set_xlabel(\"Ambient Value\", fontsize=20, color=INK)\nax.set_ylabel(\"Sensor Output\", fontsize=20, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Grid\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\n\n# Legend\nax.legend(title=\"Sensor Type\", fontsize=16, title_fontsize=18, loc=\"upper left\")\n\n# Remove top and right spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}