I’m analyzing some data that follows a more-or-less-linear dependency. Here’s a picture:

I’d like to show the dispersion around the mean for each of the vertical bins you see. What I need is (I think) the density() function, so to have a nice plot of the dispersion. However, density() returns a plot, not data. I need to combine all these plots toghether, possibly in 3 dimensions. How can I do that?

For reference, I’m thinking about something like these (pictures found on the web and with no connection):

julia> using Plots, KernelDensity
julia> data = [ randn(1000) for _ in 1:10 ]; # data for each coordinate
julia> densities = [ kde(dat).density for dat in data ]; # densities
julia> density_matrix = hcat(densities...); # turn all into a matrix
julia> surface(density_matrix) # create surface

Had to work a little due to Julia being outdated, but here I am. It works, thanks!

Now I have a problem tho: axis don’t move with GR. What I mean is that if I tilt the camera so to look at the plot from the “left”, the axis don’t move and get covered:

That’s wonderful, thanks! I think I’ll tweak it a bit tho, right now I don’t want to fit a gaussian, but I want to visualize/verify the dispersion/residuals, so I think I’m going for a kde here

Thanks to all for the interesting answers, amazing community as usual .
I’ll mark this as solved since I got an answer to the title question, then I’ll open a new thread for the axis issue.