{"spec_id":"contour-density","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\ncontour-density: Density Contour Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-16\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\n\n\n# Theme tokens (see prompts/default-style-guide.md)\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nSCATTER_COLOR = \"#4A4A44\" if THEME == \"light\" else \"#9A9A94\"\n\n# Data - bivariate normal distributions with two clusters\nnp.random.seed(42)\n\n# Main cluster\nn1 = 300\nx1 = np.random.normal(loc=5, scale=1.5, size=n1)\ny1 = np.random.normal(loc=5, scale=1.5, size=n1)\n\n# Secondary cluster\nn2 = 150\nx2 = np.random.normal(loc=9, scale=1.0, size=n2)\ny2 = np.random.normal(loc=8, scale=1.0, size=n2)\n\n# Combine clusters\nx = np.concatenate([x1, x2])\ny = np.concatenate([y1, y2])\n\n# Configure seaborn theme with theme-adaptive colors\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    },\n)\n\n# Create figure\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Density contour plot using seaborn's kdeplot (filled with viridis)\nsns.kdeplot(x=x, y=y, ax=ax, levels=10, fill=True, cmap=\"viridis\", alpha=0.8)\n\n# Add contour lines for clarity (using INK_SOFT for theme-adaptive color)\nsns.kdeplot(x=x, y=y, ax=ax, levels=10, color=INK_SOFT, linewidths=1.5, alpha=0.6)\n\n# Scatter plot overlay for context (theme-adaptive color, semi-transparent)\nax.scatter(x, y, s=15, color=SCATTER_COLOR, alpha=0.25, edgecolors=\"none\")\n\n# Styling\nax.set_xlabel(\"X Variable (units)\", fontsize=20, color=INK)\nax.set_ylabel(\"Y Variable (units)\", fontsize=20, color=INK)\nax.set_title(\"contour-density · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Remove top and right spines\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(0.8)\n\n# Subtle grid\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"}