{"spec_id":"scatter-color-mapped","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-color-mapped: Color-Mapped Scatter Plot\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-08\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.colors import Normalize\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# Data: Weather station measurements with clustered wind speed patterns\nnp.random.seed(42)\nn_points = 180\n\n# Geographic coordinates with bias toward regions\nlatitude = np.concatenate(\n    [\n        np.random.normal(40, 3, 50),  # Northern cluster\n        np.random.normal(25, 4, 50),  # Southern cluster\n        np.random.normal(35, 2, 50),  # Central cluster\n        np.random.normal(45, 5, 30),  # Northwest sparse\n    ]\n)\n\nlongitude = np.concatenate(\n    [\n        np.random.normal(-95, 4, 50),  # Central region\n        np.random.normal(-75, 3, 50),  # Eastern region\n        np.random.normal(-110, 5, 50),  # Western region\n        np.random.normal(-85, 6, 30),  # Mixed\n    ]\n)\n\n# Wind speed influenced by location with natural variability\nwind_speed = np.concatenate(\n    [\n        np.random.uniform(12, 22, 50),  # Northern: moderate to strong winds\n        np.random.uniform(8, 16, 50),  # Southern: lighter winds\n        np.random.uniform(5, 14, 50),  # Central: variable winds\n        np.random.uniform(10, 25, 30),  # Northwest: mixed conditions\n    ]\n)\n\n# Create plot (4800x2700 px at 300 dpi = 16x9 inches)\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Normalize color range\nnorm = Normalize(vmin=wind_speed.min(), vmax=wind_speed.max())\n\n# Scatter plot with viridis colormap\nscatter = ax.scatter(\n    latitude, longitude, c=wind_speed, cmap=\"viridis\", s=200, alpha=0.75, edgecolors=PAGE_BG, linewidth=1, norm=norm\n)\n\n# Colorbar with label\ncbar = plt.colorbar(scatter, ax=ax, pad=0.02)\ncbar.set_label(\"Wind Speed (m/s)\", fontsize=20, color=INK)\ncbar.ax.tick_params(labelsize=20, colors=INK_SOFT)\ncbar.outline.set_edgecolor(INK_SOFT)\n\n# Labels and styling\nax.set_xlabel(\"Latitude (°N)\", fontsize=20, color=INK)\nax.set_ylabel(\"Longitude (°W)\", fontsize=20, color=INK)\nax.set_title(\"scatter-color-mapped · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Subtle grid (y-axis preferred for scatter)\nax.yaxis.grid(True, alpha=0.2, linewidth=0.8, color=INK)\n\n# Spine styling\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    ax.spines[spine].set_linewidth(1)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}