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

**URL:** https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614
**Category:** Visualization
**Tags:** question, statistics, distributions, 3d, plot
**Created:** [October 31, 2023, 12:21pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614 "2023-10-31T12:21:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [October 31, 2023, 12:21pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/1 "2023-10-31T12:21:57Z")

</div>

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

 ![](https://global.discourse-cdn.com/julialang/original/3X/c/2/c298086b7862025cc31c7c7df71d06b2e0e1336b.jpeg)  
The closest method I found is [`density`](https://docs.makie.org/stable/reference/plots/density/) from Makie, but it doesn’t work with functions or their values per se.

How can I make such a plot?

---

<div class="post-metadata">

### Author: ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)
#### Post date: [October 31, 2023, 2:20pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/2 "2023-10-31T14:20:12Z")

</div>

Based on the code [here](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/band3d/), perhaps something like this:

```julia
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 

```

 ![pdfs](https://global.discourse-cdn.com/julialang/original/3X/0/e/0e04d3f4eff847334c96657fb4f5f91858a88973.png)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [October 31, 2023, 3:09pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/3 "2023-10-31T15:09:10Z")

</div>

Linking [related thread](https://discourse.julialang.org/t/how-can-i-combine-different-density-plots-in-a-3d-plot/96194) for more ideas.

---

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [October 31, 2023, 6:54pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/4 "2023-10-31T18:54:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [October 31, 2023, 6:55pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/5 "2023-10-31T18:55:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [October 31, 2023, 7:02pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/6 "2023-10-31T19:02:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)
#### Post date: [October 31, 2023, 7:13pm UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/7 "2023-10-31T19:13:00Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [November 2, 2023, 11:42am UTC](https://discourse.julialang.org/t/how-to-plot-a-sequence-of-probability-density-functions-as-lines-in-pseudo-3d/105614/8 "2023-11-02T11:42:25Z")

</div>

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