{"spec_id":"area-stacked-percent","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\narea-stacked-percent: 100% Stacked Area Chart\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\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# Okabe-Ito palette\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\"]\n\n# Data - Renewable energy evolution (2014-2024)\nyears = np.arange(2014, 2025)\nsolar = np.array([0.8, 1.2, 1.8, 2.5, 3.3, 4.2, 5.4, 6.8, 8.2, 9.8, 11.5])\nwind = np.array([2.1, 2.5, 3.0, 3.8, 4.6, 5.5, 6.8, 8.2, 9.6, 11.2, 13.0])\nhydro = np.array([15.2, 15.5, 15.8, 16.2, 16.5, 16.8, 17.0, 17.1, 17.2, 17.3, 17.4])\nnatural_gas = np.array([42.1, 41.8, 41.2, 40.5, 39.8, 39.0, 37.5, 35.8, 34.0, 32.5, 31.0])\ncoal = np.array([39.8, 38.5, 37.2, 36.0, 35.8, 34.5, 33.3, 32.1, 31.0, 29.0, 27.1])\n\n# Stack and normalize\ndata = np.vstack([solar, wind, hydro, natural_gas, coal])\ntotals = data.sum(axis=0)\ndata_percent = data / totals * 100\n\n# Create plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Labels\nlabels = [\"Solar\", \"Wind\", \"Hydro\", \"Natural Gas\", \"Coal\"]\n\n# Create stacked area\nax.stackplot(years, data_percent, labels=labels, colors=IMPRINT, alpha=0.85, edgecolor=PAGE_BG, linewidth=1.5)\n\n# Styling\nax.set_xlabel(\"Year (2014–2024)\", fontsize=20, color=INK)\nax.set_ylabel(\"Electricity Generation (%)\", fontsize=20, color=INK)\nax.set_title(\"area-stacked-percent · matplotlib · anyplot.ai\", fontsize=24, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Axis limits\nax.set_xlim(years[0], years[-1])\nax.set_ylim(0, 100)\n\n# Y-axis ticks with percentage labels\nax.set_yticks([0, 25, 50, 75, 100])\nax.set_yticklabels([\"0%\", \"25%\", \"50%\", \"75%\", \"100%\"], color=INK_SOFT)\n\n# X-axis ticks\nax.set_xticks(years)\nax.set_xticklabels(years, color=INK_SOFT)\n\n# Grid\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\n# Spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Legend - positioned outside plot area\nleg = ax.legend(loc=\"upper left\", bbox_to_anchor=(1.02, 1), fontsize=16, frameon=True)\nif leg:\n    leg.get_frame().set_facecolor(ELEVATED_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    leg.get_frame().set_linewidth(0.8)\n    for text in leg.get_texts():\n        text.set_color(INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}