diff --git a/src/recipes.jl b/src/recipes.jl index aeee2bc9..4105f7c5 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -505,9 +505,10 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode _span(v) = ignorenan_maximum(v) - ignorenan_minimum(v) n_samples = length(linearindices(first(vs))) - # Estimator for number of samples in one row/column of bins along each axis: - nd = n_samples^(1/(2+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]