Binning helpers for histograms.
Given a list of numeric observations, bin/2 returns the computed
{edges, values, density?} triple used by %Bland.Series.Histogram{}.
Bland.histogram/3 calls this for you at series-construction time; you
only need bin/2 directly if you want to pre-compute bin counts
outside of a figure (e.g. to render a table alongside the plot).
Bin-count strategies
- integer
N— exactly N equal-width bins :sturges—⌈1 + log₂(n)⌉(default):sqrt—⌈√n⌉:scott—⌈(max-min) / (3.49·σ·n^(-1/3))⌉:freedman_diaconis—⌈(max-min) / (2·IQR·n^(-1/3))⌉
Pass explicit bin_edges: [...] to skip strategy selection entirely.
iex> {edges, counts, _} = Bland.Histogram.bin([1, 2, 2, 3, 3, 3], bins: 3)
iex> {length(edges), counts}
{4, [1, 2, 3]}
Summary
Functions
Bins observations.
Edges computed for observations under the given strategy.
Converts {bin_edges, cumulative_probabilities} into a staircase
polyline {xs, ys} suitable for Bland.line/4.
Types
@type normalize() :: :count | :pmf | :density | :cmf
@type strategy() :: pos_integer() | :sturges | :sqrt | :scott | :freedman_diaconis
Functions
Bins observations.
Returns {bin_edges, values, normalize} where:
bin_edgesis a list of lengthn_bins + 1valuesis a list of lengthn_binsnormalizeis the requested normalization mode (one of:count,:pmf,:density,:cmf)
Normalizations
:count— raw integer counts per bin (default):pmf— probability mass per bin:count / total.Σ values = 1. Appropriate when bins are unequal width or when you want probabilities rather than densities.:density— probability density:count / (total · bin_width).Σ (values · widths) = 1. Integrates to 1 over the domain.:cmf— cumulative mass function: running sum of PMF values ([C₀, C₀+C₁, ..., 1]). Length matchescounts; seeBland.histogram/3for how this is rendered as a staircase.
Options:
:bins— bin-count strategy (default:sturges):bin_edges— explicit edge list; overrides:bins:normalize—:count | :pmf | :density | :cmf(default:count):density— shorthand fornormalize: :density. Kept for backwards compatibility.
Observations that fall outside [bin_edges |> hd, bin_edges |> List.last]
are silently dropped.
iex> {_edges, values, :pmf} = Bland.Histogram.bin([1, 2, 2, 3, 3, 3], bins: 3, normalize: :pmf)
iex> Enum.sum(values)
1.0
Edges computed for observations under the given strategy.
Converts {bin_edges, cumulative_probabilities} into a staircase
polyline {xs, ys} suitable for Bland.line/4.
The returned polyline starts at (edges |> hd, 0.0), steps
horizontally across each bin at the previous cumulative level, then
jumps vertically at the bin's right edge — the classic empirical
CDF shape.
iex> {xs, ys} = Bland.Histogram.staircase([0.0, 1.0, 2.0], [0.5, 1.0])
iex> {xs, ys}
{[0.0, 1.0, 1.0, 2.0, 2.0], [0.0, 0.0, 0.5, 0.5, 1.0]}