Merge pull request #1073 from mkborregaard/fix-2dhistogram-bins
fix 2dhistogram bins
This commit is contained in:
commit
b69c37f1bb
@ -505,8 +505,10 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode
|
|||||||
_span(v) = ignorenan_maximum(v) - ignorenan_minimum(v)
|
_span(v) = ignorenan_maximum(v) - ignorenan_minimum(v)
|
||||||
|
|
||||||
n_samples = length(linearindices(first(vs)))
|
n_samples = length(linearindices(first(vs)))
|
||||||
# Estimator for number of samples in one row/column of bins along each axis:
|
|
||||||
n = max(1, n_samples^(1/N))
|
# The nd estimator is the key to most automatic binning methods, and is modified for twodimensional histograms to include correlation
|
||||||
|
nd = n_samples^(1/(2+N))
|
||||||
|
nd = N == 2 ? nd / (1-cor(first(vs), last(vs))^2)^(3//8) : nd # the >2-dimensional case does not have a nice solution to correlations
|
||||||
|
|
||||||
v = vs[dim]
|
v = vs[dim]
|
||||||
|
|
||||||
@ -515,15 +517,15 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mode == :sqrt # Square-root choice
|
if mode == :sqrt # Square-root choice
|
||||||
_cl(sqrt(n))
|
_cl(sqrt(n_samples))
|
||||||
elseif mode == :sturges # Sturges' formula
|
elseif mode == :sturges # Sturges' formula
|
||||||
_cl(log2(n)) + 1
|
_cl(log2(n_samples) + 1)
|
||||||
elseif mode == :rice # Rice Rule
|
elseif mode == :rice # Rice Rule
|
||||||
_cl(2 * n^(1/3))
|
_cl(2 * nd)
|
||||||
elseif mode == :scott # Scott's normal reference rule
|
elseif mode == :scott # Scott's normal reference rule
|
||||||
_cl(_span(v) / (3.5 * std(v) / n^(1/3)))
|
_cl(_span(v) / (3.5 * std(v) / nd))
|
||||||
elseif mode == :fd # Freedman–Diaconis rule
|
elseif mode == :fd # Freedman–Diaconis rule
|
||||||
_cl(_span(v) / (2 * _iqr(v) / n^(1/3)))
|
_cl(_span(v) / (2 * _iqr(v) / nd))
|
||||||
elseif mode == :wand
|
elseif mode == :wand
|
||||||
wand_edges(v) # this makes this function not type stable, but the type instability does not propagate
|
wand_edges(v) # this makes this function not type stable, but the type instability does not propagate
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user