{"spec_id":"histogram-cumulative","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nhistogram-cumulative: Cumulative Histogram\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 97/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\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\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\nACCENT = \"#C475FD\"  # Okabe-Ito position 2 for reference lines\n\n# Data - exam scores with realistic distribution\nnp.random.seed(42)\nscores = np.concatenate(\n    [\n        np.random.normal(65, 10, 300),  # Average performers\n        np.random.normal(85, 5, 150),  # High performers\n        np.random.normal(45, 8, 50),  # Lower performers\n    ]\n)\nscores = np.clip(scores, 0, 100)\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Cumulative histogram with step display\nn, bins, patches = ax.hist(\n    scores,\n    bins=30,\n    cumulative=True,\n    density=True,\n    histtype=\"step\",\n    linewidth=3,\n    color=BRAND,\n    label=\"Cumulative Distribution\",\n)\n\n# Add filled area under the step function for better visibility\nax.hist(scores, bins=30, cumulative=True, density=True, histtype=\"stepfilled\", alpha=0.2, color=BRAND)\n\n# Add percentile bands using axhspan for distinctive matplotlib features\npercentiles = [25, 50, 75, 90]\nfor p in percentiles:\n    pct_value = np.percentile(scores, p)\n    ax.axhline(y=p / 100, color=ACCENT, linestyle=\"--\", linewidth=2, alpha=0.5)\n    ax.axvline(x=pct_value, color=ACCENT, linestyle=\"--\", linewidth=2, alpha=0.5)\n\n    # Position annotations to avoid overlap\n    if p == 90:\n        xytext = (pct_value - 15, p / 100 - 0.06)\n        ha = \"right\"\n    elif p == 75:\n        xytext = (pct_value - 15, p / 100 + 0.02)\n        ha = \"right\"\n    else:\n        xytext = (pct_value + 3, p / 100 + 0.03)\n        ha = \"left\"\n\n    ax.annotate(\n        f\"{p}th percentile (score ≈ {pct_value:.0f})\",\n        xy=(pct_value, p / 100),\n        xytext=xytext,\n        fontsize=14,\n        color=INK_SOFT,\n        ha=ha,\n        bbox={\"boxstyle\": \"round,pad=0.5\", \"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.8},\n    )\n\n# Style\nax.set_xlabel(\"Exam Score (points)\", fontsize=20, color=INK)\nax.set_ylabel(\"Cumulative Probability\", fontsize=20, color=INK)\nax.set_title(\"histogram-cumulative · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\nax.set_xlim(0, 100)\nax.set_ylim(0, 1.05)\n\n# Grid styling\nax.grid(True, alpha=0.15, linestyle=\"-\", linewidth=0.8, color=INK_SOFT)\nax.set_axisbelow(True)\n\n# Spine styling\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    ax.spines[s].set_linewidth(0.8)\n\n# Legend\nleg = ax.legend(fontsize=16, loc=\"lower right\")\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"}