{"spec_id":"histogram-stepwise","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nhistogram-stepwise: Step Histogram\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-05-12\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\"\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\"\n\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# Data\nnp.random.seed(42)\nvalues = np.concatenate([np.random.normal(50, 10, 200), np.random.normal(80, 8, 150)])\n\n# Compute histogram bins\ncounts, bin_edges = np.histogram(values, bins=25)\n\n# Build step coordinates for pygal.XY\n# Step histogram: horizontal segments at count levels, vertical connections\nstep_data = []\nfor i in range(len(counts)):\n    left = bin_edges[i]\n    right = bin_edges[i + 1]\n    count = counts[i]\n    # Horizontal segment for this bin\n    step_data.append((left, count))\n    step_data.append((right, count))\n\n# Add baseline at start and end\nstep_data.insert(0, (bin_edges[0], 0))\nstep_data.append((bin_edges[-1], 0))\n\n# Custom style for large canvas\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=IMPRINT,\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    stroke_width=3,\n)\n\n# Create XY chart for step lines\nchart = pygal.XY(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"histogram-stepwise · pygal · anyplot.ai\",\n    x_title=\"Value (cm)\",\n    y_title=\"Frequency (count)\",\n    show_dots=False,\n    stroke_style={\"width\": 3},\n    fill=False,\n    show_legend=False,\n    show_y_guides=True,\n    show_x_guides=False,\n    x_label_rotation=0,\n)\n\n# Add step line data\nchart.add(\"Distribution\", step_data)\n\n# Save outputs\nchart.render_to_file(f\"plot-{THEME}.html\")\nchart.render_to_png(f\"plot-{THEME}.png\")\n"}