Skip to content

Commit 586066d

Browse files
nalimilanararslan
andauthored
Document how histogram bins are chosen by default (#829)
Also avoid mentioning `sturges` in the docstring since it is not exported. Co-authored-by: Alex Arslan <[email protected]>
1 parent dd0a987 commit 586066d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/hist.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fit(::Type{Histogram{T}}, vs::NTuple{N,AbstractVector}, wv::AbstractWeights; clo
363363
fit(Histogram{T}, vs, wv, histrange(vs,_nbins_tuple(vs, nbins),closed); closed=closed)
364364

365365
"""
366-
fit(Histogram, data[, weight][, edges]; closed=:left, nbins)
366+
fit(Histogram, data[, weight][, edges]; closed=:left[, nbins])
367367
368368
Fit a histogram to `data`.
369369
@@ -377,8 +377,12 @@ Fit a histogram to `data`.
377377
bin. If no weight vector is supplied, each observation has weight 1.
378378
379379
* `edges`: a vector (typically an `AbstractRange` object), or tuple of vectors, that gives
380-
the edges of the bins along each dimension. If no edges are provided, these
381-
are determined from the data.
380+
the edges of the bins along each dimension. If no edges are provided, they are chosen
381+
so that approximately `nbins` bins of equal width are constructed along each dimension.
382+
383+
!!! note
384+
In most cases, the number of bins will be `nbins`. However, to ensure that the bins have
385+
equal width, more or fewer than `nbins` bins may be used.
382386
383387
# Keyword arguments
384388
@@ -387,6 +391,8 @@ Fit a histogram to `data`.
387391
388392
* `nbins`: if no `edges` argument is supplied, the approximate number of bins to use
389393
along each dimension (can be either a single integer, or a tuple of integers).
394+
If omitted, it is computed using Sturges's formula, i.e. `ceil(log2(length(n))) + 1`
395+
with `n` the number of data points.
390396
391397
# Examples
392398

0 commit comments

Comments
 (0)