{"spec_id":"histogram-cumulative","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nhistogram-cumulative: Cumulative Histogram\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 86/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pygal\nfrom pygal.style import Style\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_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"\n\n# Data - Customer satisfaction ratings on 1-5 scale from 1000 customers\nnp.random.seed(42)\nratings = np.random.normal(loc=3.7, scale=0.8, size=1000)\nratings = np.clip(ratings, 1, 5)\n\n# Compute histogram bins and cumulative counts\nbin_count = 20\ncounts, bin_edges = np.histogram(ratings, bins=bin_count)\ncumulative_counts = np.cumsum(counts)\ncumulative_proportions = cumulative_counts / len(ratings)\n\n# Create bin labels\nbin_labels = [f\"{bin_edges[i]:.1f}-{bin_edges[i + 1]:.1f}\" for i in range(len(bin_edges) - 1)]\n\n# Style for large canvas (4800x2700)\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=(BRAND,),\n    title_font_size=28,\n    label_font_size=22,\n    major_label_font_size=18,\n    legend_font_size=16,\n    value_font_size=14,\n)\n\n# Create bar chart for cumulative histogram\nchart = pygal.Bar(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"histogram-cumulative · pygal · anyplot.ai\",\n    x_title=\"Customer Satisfaction Rating\",\n    y_title=\"Cumulative Proportion\",\n    show_legend=False,\n    show_y_guides=True,\n    show_x_guides=False,\n    x_label_rotation=45,\n    range=(0, 1.05),\n)\n\n# Set x-axis labels\nchart.x_labels = bin_labels\n\n# Add cumulative proportion data\nchart.add(\"Cumulative\", cumulative_proportions.tolist())\n\n# Save outputs\nchart.render_to_file(f\"plot-{THEME}.html\")\nchart.render_to_png(f\"plot-{THEME}.png\")\n"}