Closed juliohm closed 7 years ago
I'm afraid that there is no recipe for 2D density plots, so you'd need to do something like:
s = kde(randn(1000,2))
heatmap(s.x, s.y, s.density)
to get what you want.
We were planning to add one such recipe here but nobody has made a PR yet.
@piever what is the recipe at StatPlots.jl for? https://github.com/JuliaPlots/StatPlots.jl/blob/master/src/StatPlots.jl#L18
Also, the snippet of code provided doesn't work like in the recipe.
Ups, I was blind. That recipe is only be meant to be used for plots representing a 2D distribution:
heatmap(kde(randn(1000,2)))
contourf(kde(randn(1000,2)))
surface(kde(randn(1000,2)))
When you try plot(kde(randn(1000,2)))
it gets translated to
s = kde(randn(1000,2))
plot(s.x, s.y, s.density)
which will not work as a plot command. (EDIT: I was wrong, see below)
What's the issue with the snippet of code I provided above, except being a bit annoying to type all the time?
What I meant as a future plan is to have something like density(x, y)
being translated to contourf(kde([x y]))
. It'd be consistent with density(x)
for univariate distributions which is implemented already.
Actually you were right in that plot(kde(randn(1000,2)))
gets translated to contour(kde(randn(1000,2)))
that is to say:
s = kde(randn(1000,2))
contour(s.x, s.y, s.density)
But I suspect that it is bugged because it changes the order of x and y. Does
s = kde(randn(1000,2))
contour(s.x, s.y, s.density')
do what you want reliably?
Let me know if that solves it so that I can update the recipe at https://github.com/JuliaPlots/StatPlots.jl/blob/master/src/StatPlots.jl#L18
It works nicely @piever , could you please go ahead and fix the order? Thank you very much.