{"spec_id":"scatter-color-mapped","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nscatter-color-mapped: Color-Mapped Scatter Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 83/100 | Updated: 2026-05-08\n\"\"\"\n\nimport os\nimport sys\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\nsys.path = [p for p in sys.path if p and os.path.abspath(p) != os.path.dirname(__file__)]\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\n# Data - Air quality index measurements across cities\nnp.random.seed(42)\nn_cities = 200\n\n# Geographic coordinates (latitude, longitude)\nlatitude = np.random.uniform(25, 50, n_cities)\nlongitude = np.random.uniform(-130, -65, n_cities)\n\n# Air quality index as color variable - higher in urban areas\nurban_density = np.exp(-((latitude - 40) ** 2 + (longitude + 90) ** 2) / 400)\naqi = 30 + urban_density * 70 + np.random.normal(0, 5, n_cities)\naqi = np.clip(aqi, 10, 150)\n\n# Create figure\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Scatter plot with color mapping\nscatter = ax.scatter(longitude, latitude, c=aqi, s=150, cmap=\"viridis\", alpha=0.7, edgecolors=PAGE_BG, linewidth=0.5)\n\n# Colorbar with theme-adaptive styling\ncbar = fig.colorbar(scatter, ax=ax, pad=0.02)\ncbar.set_label(\"Air Quality Index\", fontsize=20, color=INK)\ncbar.ax.tick_params(labelsize=16, colors=INK_SOFT)\nfor spine in cbar.ax.spines.values():\n    spine.set_color(INK_SOFT)\n\n# Styling\nax.set_xlabel(\"Longitude (°W)\", fontsize=20, color=INK)\nax.set_ylabel(\"Latitude (°N)\", fontsize=20, color=INK)\nax.set_title(\"scatter-color-mapped · seaborn · anyplot.ai\", fontsize=24, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\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\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}