# Projecting Histograms in 3D

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.

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

If you can drop the 3D requirement maybe ridge plots could be helpful. You could adapt something like this with PyPlot.jl.

1 Like

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

Might a violin plot help? They are available in Statsplots, check the readme here: https://github.com/JuliaPlots/StatsPlots.jl

1 Like

A similar example in PGFPlotsX with bells & whistles:

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

3 Likes

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:

``````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")
``````

2 Likes