# Histogram Bin Calculator

Work out how many bins a histogram needs. Compare Sturges, Scott, Freedman-Diaconis, Rice and square-root, then get the bin edges, counts and percentages.

## Run it

- **CLI:** `gizza tool histogram-bin-calculator "1
2
2
3
4
7
8
9
12
15
22
40"`
- **Web:** https://gizza.ai/tools/histogram-bin-calculator/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/histogram-bin-calculator/tool.json

## Inputs

- `numbers` — Numbers _(field)_
- `rule` — Bin-count rule to apply _(field)_
- `bins` — Bin count (used when the rule is Manual) _(field)_
- `range_min` — Range start (blank = smallest value) _(field)_
- `range_max` — Range end (blank = largest value) _(field)_
- `nice_edges` — Round bin width and first edge to human-friendly steps _(field)_
- `right_closed` — Right-closed intervals (a, b] instead of [a, b) _(field)_
- `precision` — Decimal places _(field)_
- `output` — Output _(field)_
- `cumulative` — Add cumulative count and cumulative percent columns _(field)_
- `density` — Add a density column, count / (n × bin width) _(field)_
- `chart` — Draw an ASCII bar per bin (report output) _(field)_

## Output

- Result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `numbers` — Numbers
- `rule` — Bin-count rule to apply
- `bins` — Bin count (used when the rule is Manual)
- `range_min` — Range start (blank = smallest value)
- `range_max` — Range end (blank = largest value)
- `nice_edges` — Round bin width and first edge to human-friendly steps
- `right_closed` — Right-closed intervals (a, b] instead of [a, b)
- `precision` — Decimal places
- `output` — Output
- `cumulative` — Add cumulative count and cumulative percent columns
- `density` — Add a density column, count / (n × bin width)
- `chart` — Draw an ASCII bar per bin (report output)

Example: `https://gizza.ai/tools/histogram-bin-calculator/?numbers=1%0A2%0A2%0A3%0A4%0A7%0A8%0A9%0A12%0A15%0A22%0A40&rule=auto&bins=10&range_min=0&range_max=40&nice_edges=true&right_closed=true&precision=4&output=report&cumulative=true&density=true&chart=true`

---

## About this tool

A histogram turns numeric data into ranges and counts, but the result changes a lot depending on the bin width. This calculator compares several common rules side by side — Sturges, Scott, Freedman-Diaconis, Rice, and square-root — then applies the rule you choose and prints the resulting bin edges, counts, percentages, and optional cumulative or density columns.

Use it when you have a pasted column from a spreadsheet, experiment, log, or small dataset and want a principled starting point before drawing a histogram. Sturges is simple and often smooth for small samples, Scott uses the sample standard deviation, and Freedman-Diaconis uses the IQR so it is less sensitive to outliers.

### Worked example

Paste this dataset:

```text
1,2,2,3,3,3,4,5,7,9,12
```

With the default `auto` rule, the output first shows the sample summary and every rule's recommended bin count and width. It then builds a histogram table for the selected rule, with interval labels, counts, percentages, and ASCII bars so you can see the distribution shape immediately.

### Input notes and limits

Numbers can be separated by newlines, commas, spaces, tabs, semicolons, or pipes. Use plain decimals or scientific notation such as `12`, `-3.5`, or `1.2e3`; strip currency symbols and thousands separators first. The tool accepts 2 to 100,000 finite values and caps manual/rule-generated bins at 1,000 rows.

## FAQ

<details>
<summary>Which bin rule should I use?</summary>

Start with `auto`, then compare the rule table. Sturges is often reasonable for small, roughly normal samples. Scott can work well for normal-ish data but is pulled by outliers. Freedman-Diaconis uses the IQR and is usually more robust for skewed data.

</details>

<details>
<summary>What does the auto rule do?</summary>

`auto` chooses the finer of Sturges and Freedman-Diaconis, similar to NumPy's default. It keeps Sturges from being too coarse while still falling back when the IQR rule is not informative.

</details>

<details>
<summary>Why do my bin edges look awkward?</summary>

Rule-derived widths are mathematical, so edges can land on values like `1.4286`. Turn on `nice_edges` to round the width up to a 1/2/2.5/5 × power-of-ten step and snap the first edge down when the range start is automatic.

</details>

<details>
<summary>What is density?</summary>

Density is `count / (n × bin_width)`, the bar height for a unit-area histogram. It is useful when comparing histograms with different bin widths or sample sizes.

</details>

<details>
<summary>How are edge values assigned?</summary>

By default bins are left-closed (`[a, b)`) and the final bin includes the maximum. Enable `right_closed` to use `(a, b]`, where values exactly on an edge fall into the lower bin.

</details>

## Related tools

- [Absolute value, sign, or negation for a whole column](https://gizza.ai/tools/absolute-value-transformer/): Paste a column of numbers and apply absolute value, sign extraction (-1/0/1), sign flipping, or force-negative to every value at once, with rounding and an audit table.
- [Adjacency Matrix Converter](https://gizza.ai/tools/adjacency-matrix-converter/): Convert a graph between edge list, adjacency matrix, and incidence matrix — directed or undirected, weighted or not. Free, private, runs in your browser.
- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [ARFF Converter](https://gizza.ai/tools/arff-converter/): Convert Weka ARFF datasets to CSV and CSV tables back to ARFF locally — nominal attributes, numeric types, dates, sparse rows, missing values, and type rows.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
