# 3d BarPlot with Makie.jl

**URL:** <https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [June 19, 2024, 1:19pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861 "2024-06-19T13:19:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilippA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philippa/32/21676_2.png) [@PhilippA](https://discourse.julialang.org/u/PhilippA)\
**Post date:** [June 19, 2024, 1:19pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861/1 "2024-06-19T13:19:25Z")

</div>

I would like to visualise a simple pdf of a bivariate discrete distribution. Is it possible to do a simple 3D bar plot in Makie.jl, similar to this solution:  
[https://www.wolfram.com/mathematica/new-in-8/new-and-improved-scientific-and-information-visualization/visualize-bivariate-discrete-distribution-function.html](https://www.wolfram.com/mathematica/new-in-8/new-and-improved-scientific-and-information-visualization/visualize-bivariate-discrete-distribution-function.html)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 19, 2024, 1:23pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861/2 "2024-06-19T13:23:11Z")

</div>

Just made this example in another thread [GLMakie: Create 3D animations with GLMakie? - #2 by jules](https://discourse.julialang.org/t/glmakie-create-3d-animations-with-glmakie/115850/2)

---

<div class="post-metadata">

**Author:** ![Pablo\_Marchant](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablo_marchant/32/32828_2.png) [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Post date:** [June 19, 2024, 1:23pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861/3 "2024-06-19T13:23:51Z")

</div>

Also searching a bit there’s this other thread that has some examples:

> [@3d bars makie, colors and meshes](https://discourse.julialang.org/t/3d-bars-makie-colors-and-meshes/70283/6):
>
> Oh sorry, I read over that part. I don’t think you can get that with meshscatter right now. With mesh you could use mesh!(ax, recmesh; color=last.(coordinates(recmesh)), colormap = :Spectral\_11, colorrange = (0, 1), shading=false) but that just intepolates between two colors: Alternatively you could work with a texture similar to [Issues · MakieOrg/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/issues/1368:) function test3dBars() x = y= 1:10 z = rand(10,10) δx = (x[2] - x[1]) / 2 …

---

<div class="post-metadata">

**Author:** ![PhilippA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philippa/32/21676_2.png) [@PhilippA](https://discourse.julialang.org/u/PhilippA)\
**Post date:** [June 20, 2024, 2:10pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861/4 "2024-06-20T14:10:17Z")

</div>

Thanks a lot! Unfortunately, I am still struggling to understand the API.  
My bars are shifted and I do not know how to solve it.

```julia
# Table below shows discrete distribution 
# X values in rows, Y values in columns
# For example, P(X = 2, Y = 1) = 0.01
xy_probs = [0.06 0.14 0.03 0.25 0.00;
        0.01 0.02 0.05 0.06 0.09;
        0.06 0.15 0.00 0.04 0.02]

xy_vals = [(x, y) for x in 1:3 for y in 1:5]
z = [xy_probs[x, y] for (x, y) in xy_vals]

meshscatter(xy_vals,
            markersize = [Vec3f(1, 1, z) for z in z], 
            marker = Rect3f((0.1, 0.1, 0), (0.1, 0.1, 1)), 
            axis = (; type = Axis3))

```

I also do not fully understand `markersize` and the input to `Rect3f(...)`. I have not found any helpful documentation for the latter. Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 20, 2024, 3:34pm UTC](https://discourse.julialang.org/t/3d-barplot-with-makie-jl/115861/5 "2024-06-20T15:34:11Z")

</div>

`Rect3f((0, 0, 0), (1, 1, 1))` is a cube with widths 1, 1, 1 and the origin corner at 0, 0, 0. In my example I chose `(-0.5, -0.5, 0), (1, 1, 1)` so that the base marker sits centered on the xy plane on the point where it’s placed. When you then give it a Vec3f markersize where you only scale z, like `Vec3f(1, 1, 10)`, then you get a bar that goes from z = 0 to z = 10.
