# Projecting Histograms in 3D

**URL:** <https://discourse.julialang.org/t/projecting-histograms-in-3d/43149>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [July 15, 2020, 11:32pm UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149 "2020-07-15T23:32:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Slagle](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@Ian\_Slagle](https://discourse.julialang.org/u/Ian_Slagle)\
**Post date:** [July 15, 2020, 11:32pm UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/1 "2020-07-15T23:32:05Z")

</div>

Is it possible to make a plot like this in Julia? I’ve looked into plot3d, but I can’t get histograms to work with it.

 ![](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c5ffccbeb2f6b69e2943f1aa2d007c3aa356325.png)

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [July 16, 2020, 1:25am UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/2 "2020-07-16T01:25:56Z")

</div>

Not a simple solution, but you could adapt the code here to work with PlotlyJS.jl:

> **[Adding a shape to a 3D plot](https://community.plotly.com/t/adding-a-shape-to-a-3d-plot/1441)**
>
> Is it possible to add a shape to a 3D plot? I am trying to add a “floor” to my 3D plot. I tried using add\_trace with a shape, but not having any luck getting the shape to show up. Should this work? or is there a better approach. Basically, I...

---

<div class="post-metadata">

**Author:** ![IlyaOrson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilyaorson/32/1681_2.png) [@IlyaOrson](https://discourse.julialang.org/u/IlyaOrson)\
**Post date:** [July 16, 2020, 4:44am UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/3 "2020-07-16T04:44:36Z")

</div>

If you can drop the 3D requirement maybe ridge plots could be helpful. You could adapt something [like this](https://matplotlib.org/matplotblog/posts/create-ridgeplots-in-matplotlib/) with PyPlot.jl.

---

<div class="post-metadata">

**Author:** ![Ian\_Slagle](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@Ian\_Slagle](https://discourse.julialang.org/u/Ian_Slagle)\
**Post date:** [July 16, 2020, 4:55am UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/4 "2020-07-16T04:55:29Z")

</div>

The 3d requirement isn’t strict; I just need a way to distinguish multiple histograms. Ridge plots would work just as well, I think. Along with @robsmith11 's suggestion, both require implementing (relatively) complicated graph structures into Plotly manually, which is something I’ve not done before. I’ll look into doing this and see if it’s something I can get working reasonably quickly

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 16, 2020, 8:39am UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/5 "2020-07-16T08:39:34Z")

</div>

Might a violin plot help? They are available in Statsplots, check the readme here: [GitHub - JuliaPlots/StatsPlots.jl: Statistical plotting recipes for Plots.jl](https://github.com/JuliaPlots/StatsPlots.jl)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 16, 2020, 8:47am UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/6 "2020-07-16T08:47:23Z")

</div>

A similar example in PGFPlotsX with bells & whistles:

[https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/gallery.html#D-Waterfall](https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/gallery.html#D-Waterfall)

---

<div class="post-metadata">

**Author:** ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)\
**Post date:** [July 17, 2020, 5:42pm UTC](https://discourse.julialang.org/t/projecting-histograms-in-3d/43149/7 "2020-07-17T17:42:56Z")

</div>

> The 3d requirement isn’t strict; I just need a way to distinguish multiple histograms

If I wanted to compare 4 histograms, I personally would not use a 3D plot. I find them too difficult to compare; e.g., in the first post, I find it difficult to assess differences in the mean and variance.

Instead, I would probably use a combination of a stacked histogram and density plot, such as the following:

```julia
using StatsPlots, Distributions, Plots.PlotMeasures
gr()
# data
data1 = rand(Distributions.Normal(0, 1), 1000);
data2 = rand(Distributions.Normal(1, 1), 1000);
data3 = rand(Distributions.Normal(3,1), 1000);
data4 = rand(Distributions.Normal(0,3), 1000);

# stacked histogram
hist1 = histogram(data1, color=:blue, legend=false, ylabel="Counts", xticks=nothing, title="Stacked histograms");
hist2 = histogram(data2, color=:orange, legend=false, ylabel="Counts", xticks=nothing);
hist3 = histogram(data3, color=:green, legend=false, ylabel="Counts", xticks=nothing);
hist4 = histogram(data4, color=:red, legend=false, ylabel="Counts", xlabel="Response");

stackedhist = plot(hist1, hist2, hist3, hist4, layout=(4,1), link=:x);

# overlay of density plots
densityoverlay = density(vcat(data1, data2, data3, data4), group=repeat(["data1", "data2", "data3", "data4"], inner=1000), xlabel="Response", ylabel="Density", linewidth=2, title="Density overlay", legend=:topleft);

# combined plot
combiendplot = plot(stackedhist, densityoverlay, size=(1200,800), right_margin=10mm)
savefig(combiendplot, "multiple_histograms_test.png")

```

 ![multiple_histograms_test](https://global.discourse-cdn.com/julialang/original/3X/5/c/5c881e40d322b437b945f6aa96d1577c387bb09e.png)
