How to plot a sequence of probability density functions as lines in (pseudo) 3D?

Given a set of PDFs f1(x), f2(x) etc., I’d like to plot something like this:


The closest method I found is density from Makie, but it doesn’t work with functions or their values per se.

How can I make such a plot?

Based on the code here, perhaps something like this:

using GLMakie
using Distributions

fig = Figure()
ax = Axis3(fig[1,1])
yr = 1975:2015
xs = range(-15,10,length=200)
μs = range(-14,9,length=length(yr))
σs = range(1.0, 5.0, length=length(yr))

for i ∈ eachindex(yr)
    zs = pdf.(Normal(μs[i], σs[i]), xs)
    band!(ax, Point3f.(tuple.(xs, yr[i], 0.0)), Point3f.(tuple.(xs, yr[i], zs )); color = zs, alpha = 0.75)
end
xlims!(ax, -15, 10)
ylims!(ax, 1975, 2015)
zlims!(ax, 0.0, 0.4)
fig 

Linking related thread for more ideas.

1 Like

Thanks! Is there an short way to render it with lines? Changing band to lines results in an error.

It has some nice examples, thanks! I’ve learnt it’s called the waterfall plot.

1 Like

This looks like a plot I’ve seen before. Growth at Risk paper? Are you in econ?

Sure, replace the line that has band! with the line

lines!(ax, xs, fill(yr[i],length(xs)), zs; color = :black, lw = 1.0)

You can use both too, if you like if you put the the above command below the band! line.

1 Like

It the first example I found. I simply need to visualize and compare some PDFs.

1 Like