{"spec_id":"histogram-stacked","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nhistogram-stacked: Stacked Histogram\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 93/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 - using first 3 colors in canonical order\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\n# Data - Response times (ms) for three different server regions\nnp.random.seed(42)\n\nus_east = np.random.normal(loc=45, scale=12, size=200)\neurope = np.random.normal(loc=65, scale=15, size=180)\nasia = np.random.normal(loc=80, scale=20, size=150)\n\nus_east = np.clip(us_east, 10, 120)\neurope = np.clip(europe, 15, 140)\nasia = np.clip(asia, 20, 160)\n\nlabels = [\"US-East\", \"Europe\", \"Asia-Pacific\"]\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nax.hist(\n    [us_east, europe, asia],\n    bins=20,\n    stacked=True,\n    color=IMPRINT,\n    label=labels,\n    edgecolor=PAGE_BG,\n    linewidth=0.5,\n    alpha=0.9,\n)\n\n# Style\nax.set_xlabel(\"Response Time (ms)\", fontsize=20, color=INK)\nax.set_ylabel(\"Number of Requests\", fontsize=20, color=INK)\nax.set_title(\"histogram-stacked · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\nfor s in (\"top\", \"right\"):\n    ax.spines[s].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\n\nleg = ax.legend(fontsize=16, loc=\"upper right\", 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    plt.setp(leg.get_texts(), color=INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}