# 3d histogram plot with PGFPlotsX and StatsBase

**URL:** <https://discourse.julialang.org/t/3d-histogram-plot-with-pgfplotsx-and-statsbase/49413>\
**Category:** New to Julia\
**Tags:** plotting, pgfplot\
**Created:** [November 1, 2020, 2:12pm UTC](https://discourse.julialang.org/t/3d-histogram-plot-with-pgfplotsx-and-statsbase/49413 "2020-11-01T14:12:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [November 1, 2020, 2:12pm UTC](https://discourse.julialang.org/t/3d-histogram-plot-with-pgfplotsx-and-statsbase/49413/1 "2020-11-01T14:12:21Z")

</div>

Hi,

I would like to do something similiar like this

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

with PGFPlotsX. I´m a newbie in plotting with PGFPlotsX. I tried to it analogously like the example.

> **[3d\_waterfall.pdf](https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/3d_waterfall.pdf)**
>
> 62.70 KB

I use `StatsBase` for plotting the histogram.

Here first the code of a 2d histogram.

```julia
using Random
using Distributions
using PGFPlotsX
using Plots
plotly()
using StatsBase: fit
using StatsBase: Histogram

dists = [randn(1000, 1) for i in 1:4]

# create axis
axis = @pgf Axis(
    {
        grid = "both",
        xmax = maximum(dists[1]),
        xmin = minimum(dists[1]),
        xlabel="x",
        ylabel="y",
        xtick = collect(round(minimum([minimum(dists[i]) for i in 1:length(dists)]), digits=1):0.5:round(maximum([maximum(dists[i]) for i in 1:length(dists)]), digits=1)),
        ytick = collect(0:20:100),
        xticklabel = raw"$\pgfmathprintnumber\tick$",
        "xticklabel style" =
        {
            "rotate"=90,
            "anchor"="east",
            font = raw"\tiny"
        },
    },
)

# draw histogram
hist1 = @pgf Plot(
    {
    fill_opacity = 0.65,
    color = "blue",
    fill = "blue",
    "ybar interval"
    },
    Table(fit(Histogram, vec(dists[1]), closed = :left, nbins=40)))

push!(axis, hist1)

# draw red line
line = @pgf Plot(
        {
            color = "red",
            style ="{dashed}"
        },
        Coordinates(
            [
                (0.25, 0),
                (0.25, 100),

            ]
        )
)
push!(axis, line)

#save plot
path = (@ __DIR__ ) * raw"\histogram.tex"
pgfsave(path, axis, include_preamble=true, dpi=150)

```

When I would like to plot it in a 3d graph, then I think, that I´ve to extract the values of the histogram for my x- and y-axis of the Table in the 3d plot to plot it analogously like the 3d waterfall example .

```julia
curve = Plot3(
            {
                no_marks,
                style = {thick},
                color = "blue"
            },
#######################################
            Table(x = x_pnts,
                  y = (length(dists) - i) * ones(length(x_pnts)),
                  z = dat_pdf[i](x_pnts))
#######################################
        )

```

Does somebody know how to do it or has an alternative?

---

<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:** [November 2, 2020, 3:23pm UTC](https://discourse.julialang.org/t/3d-histogram-plot-with-pgfplotsx-and-statsbase/49413/2 "2020-11-02T15:23:24Z")

</div>

I don’t have time to work out an example now, but I am not 100% sure that pgfplots histograms also work in 3D, so that would be the first thing to check. Generally, it is best to look up the solution using LaTeX, and convert it to PGFPlotsX then.

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [November 3, 2020, 8:32am UTC](https://discourse.julialang.org/t/3d-histogram-plot-with-pgfplotsx-and-statsbase/49413/3 "2020-11-03T08:32:23Z")

</div>

> [@Tamas\_Papp](#):
>
> but I am not 100% sure that pgfplots histograms also work in 3D

I think, this is true. I found several attempts to find a workaround for a 3D histogram in pgfplots, so I guess they are just made, because pgfplots hasn´t it right away
