{"spec_id":"heatmap-stripes-climate","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nheatmap-stripes-climate: Climate Warming Stripes\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-06-02\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    after_stat,\n    element_rect,\n    element_text,\n    geom_tile,\n    ggplot,\n    guides,\n    labs,\n    scale_fill_gradient2,\n    scale_x_continuous,\n    scale_y_continuous,\n    theme,\n    theme_void,\n)\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Theme-adaptive Chrome\")\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\n\n# Data\nnp.random.seed(42)\nyears = np.arange(1850, 2025)\nn_years = len(years)\n\nbase_trend = np.linspace(-0.3, 0.2, n_years)\nyears_since_1980 = np.maximum(years - 1980, 0).astype(float)\nacceleration = years_since_1980**1.6 * 0.0008\nnoise = np.random.normal(0, 0.08, n_years)\nanomaly = base_trend + acceleration + noise\nanomaly -= np.mean(anomaly[(years >= 1961) & (years <= 1990)])\n\ndf = pd.DataFrame({\"year\": years, \"anomaly\": anomaly})\n\n# Plot\nvmax = max(abs(anomaly.min()), abs(anomaly.max()))\n\ntitle = \"heatmap-stripes-climate · python · plotnine · anyplot.ai\"\nn = len(title)\ntitle_size = round(12 * (67 / n)) if n > 67 else 12\n\nplot = (\n    ggplot(df, aes(x=\"year\", y=after_stat(\"1\"), fill=\"anomaly\"))\n    + geom_tile(aes(width=1, height=1))\n    + scale_fill_gradient2(low=\"#4467A3\", mid=PAGE_BG, high=\"#AE3030\", midpoint=0, limits=(-vmax, vmax))\n    + scale_x_continuous(expand=(0, 0))\n    + scale_y_continuous(expand=(0, 0))\n    + guides(fill=False)\n    + labs(title=title)\n    + theme_void()\n    + theme(\n        figure_size=(8, 4.5),\n        plot_title=element_text(size=title_size, ha=\"center\", weight=\"bold\", color=INK, margin={\"b\": 10}),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        plot_margin=0.01,\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}