JuliaStats / KernelDensity.jl

Kernel density estimators for Julia
Other
172 stars 40 forks source link

why permutedims? #118

Open lmiq opened 8 months ago

lmiq commented 8 months ago

https://github.com/JuliaStats/KernelDensity.jl/blob/ae70f461b6ac54c6d3d5e870deb140d21a8a8153/src/bivariate.jl#L21

Why do we carry this permutedims? This requires that StatsPlots explicitly perform the inverse transformation to plot a kde correctly, and it makes Plots default functions to plot the kde incorrectly with the most simple interpretation of the result:

julia> using Plots, KernelDensity

julia> x =  vcat(randn(1000), 10 .+ randn(1000));

julia> y = randn(2000);

julia> d = kde((x,y));

julia> heatmap(d.x, d.y, d.density)

julia> scatter!(Tuple.(zip(x,y))

produces:

image

for the records,

julia> heatmap(d.x, d.y, permutedims(d.density))

will produce the correct plot.