How can I combine different density plots in a 3D plot?

Hi all!

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

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):
2D/3D Acoustic Propagation Modeling
^ This, but of course “following” my data
Screenshot from 2023-03-16 17-32-18
^ Or this

Thanks!

Here one example:

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

gives you:

image

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

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:

    plot(density_matrix, st = :surface, xlabel="Binary weight", ylabel="Power",
        zlabel="Density",
        zlims=(0,200),
        c=cgrad(:heat, scale = :exp),
        camera = (-45,50)
    ) # create surface
    gui()

post

How can I move axis and labels so that they are visible?

I don’t know if this will be helpful, but I did this several years ago:

image

The code is here: GitHub - mthelm85/regression-plot: Cool 3D waterfall/scatter plot for regression

3 Likes

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

1 Like

For completeness, here is another example:

https://kristofferc.github.io/PGFPlotsX.jl/v1/examples/gallery/#D-Waterfall

1 Like

Maybe this example is also useful: How to produce a waterfall plot in Julia? - #3 by sijo

See also my answer (the last one) to this question: Multiple normal distributions in one 3D plot

Thanks to all for the interesting answers, amazing community as usual :heart:.
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.