{"spec_id":"ridgeline-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nridgeline-basic: Basic Ridgeline Plot\nLibrary: matplotlib 3.11.1 | Python 3.13.14\nQuality: 92/100 | Updated: 2026-07-25\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.colors import LinearSegmentedColormap\nfrom scipy import stats\n\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 - Monthly temperature distributions (Northern Hemisphere)\nnp.random.seed(42)\n\nmonths = [\n    \"January\",\n    \"February\",\n    \"March\",\n    \"April\",\n    \"May\",\n    \"June\",\n    \"July\",\n    \"August\",\n    \"September\",\n    \"October\",\n    \"November\",\n    \"December\",\n]\n\nbase_temps = [2, 4, 8, 14, 18, 22, 25, 24, 20, 14, 8, 4]\ndata = {}\nfor i, month in enumerate(months):\n    variation = 4 if i in [3, 4, 9, 10] else 3\n    data[month] = np.random.normal(base_temps[i], variation, 150)\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nx_range = np.linspace(-10, 40, 500)\noverlap = 0.6\nscale = 2.5\n\n# Imprint sequential colormap (brand green -> blue) drives the 12 ordered\n# ridges; January (top ridge) anchors at the mandated first-series #009E73.\nimprint_seq = LinearSegmentedColormap.from_list(\"imprint_seq\", [\"#009E73\", \"#4467A3\"])\ncolors = imprint_seq(np.linspace(0, 1, len(months)))\n\nfor i, month in enumerate(reversed(months)):\n    y_offset = i * (1 - overlap)\n    values = data[month]\n\n    kde = stats.gaussian_kde(values)\n    density = kde(x_range) * scale\n\n    ax.fill_between(\n        x_range,\n        y_offset,\n        y_offset + density,\n        alpha=0.8,\n        color=colors[len(months) - 1 - i],\n        edgecolor=PAGE_BG,\n        linewidth=1.5,\n    )\n    ax.plot(x_range, [y_offset] * len(x_range), color=INK_SOFT, linewidth=0.5, alpha=0.3)\n\n# Y-ticks\ny_positions = [(len(months) - 1 - i) * (1 - overlap) for i in range(len(months))]\nax.set_yticks(y_positions)\nax.set_yticklabels(months, fontsize=8, color=INK_SOFT)\n\n# Style\nax.set_xlabel(\"Temperature (°C)\", fontsize=10, color=INK)\nax.set_title(\"ridgeline-basic · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"x\", labelsize=8, colors=INK_SOFT)\nax.set_xlim(-10, 40)\n\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"left\"].set_visible(False)\nax.spines[\"bottom\"].set_color(INK_SOFT)\n\nax.grid(True, axis=\"x\", alpha=0.15, color=INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}