{"spec_id":"histogram-cumulative","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nhistogram-cumulative: Cumulative Histogram\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import *\n\n\nLetsPlot.setup_html()\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\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Response times in milliseconds (realistic API monitoring scenario)\nnp.random.seed(42)\nresponse_times = np.concatenate(\n    [\n        np.random.exponential(scale=50, size=400),  # Normal requests\n        np.random.exponential(scale=150, size=80),  # Slower requests\n        np.random.uniform(300, 500, size=20),  # Occasional slow outliers\n    ]\n)\n\n# Compute cumulative histogram data\nn_bins = 25\ncounts, bin_edges = np.histogram(response_times, bins=n_bins)\ncumulative_counts = np.cumsum(counts)\n\ndf = pd.DataFrame({\"xmin\": bin_edges[:-1], \"xmax\": bin_edges[1:], \"ymin\": 0, \"ymax\": cumulative_counts})\n\n# Plot\nplot = (\n    ggplot(df)\n    + geom_rect(aes(xmin=\"xmin\", xmax=\"xmax\", ymin=\"ymin\", ymax=\"ymax\"), fill=BRAND, color=BRAND, alpha=0.85, size=0.5)\n    + labs(x=\"Response Time (ms)\", y=\"Cumulative Count\", title=\"histogram-cumulative · letsplot · anyplot.ai\")\n    + scale_x_continuous(expand=[0.02, 0])\n    + scale_y_continuous(expand=[0, 0, 0.05, 0])\n    + theme_minimal()\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        panel_grid_major=element_line(color=INK, size=0.3),\n        panel_grid_minor=element_blank(),\n        axis_title=element_text(size=20, color=INK),\n        axis_text=element_text(size=16, color=INK_SOFT),\n        axis_line=element_line(color=INK_SOFT),\n        plot_title=element_text(size=24, color=INK),\n    )\n    + ggsize(1600, 900)\n)\n\n# Save with absolute paths\nscript_dir = os.path.dirname(os.path.abspath(__file__))\npng_path = os.path.join(script_dir, f\"plot-{THEME}.png\")\nhtml_path = os.path.join(script_dir, f\"plot-{THEME}.html\")\n\nggsave(plot, png_path, scale=3)\nggsave(plot, html_path)\n"}