# Array of boxes using Makie and volume

**URL:** <https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350>\
**Category:** Visualization\
**Created:** [August 9, 2019, 10:55am UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350 "2019-08-09T10:55:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 9, 2019, 10:55am UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/1 "2019-08-09T10:55:48Z")

</div>

Hi,  
the examples from the Makie documentation show how to build a cube (using volume), but if I try to update the scene with a new one, they overlap. Any ideas on how to solve this. I want to create an array of cubes.

```julia
using Makie
r = LinRange(-4, 4, 100); # our value range, cube centered at 0 
r1 = LinRange(5, 8, 100); # our value range, cube centered at 6

 ρ(x, y, z) = exp(-(abs(0.1*x^2))) # function (charge density)

scene = Scene(backgroundcolor = :black)

 volume!(
     scene,
     r, r, r, # coordinates to plot on
     ρ, # charge density (functions as colorant)
     algorithm = :mip # maximum-intensity-projection
 )
volume!(
     scene,
     r1, r1, r1, # coordinates to plot on
     ρ, # charge density (functions as colorant)
     algorithm = :mip # maximum-intensity-projection
 )
 scene[Axis].names.textcolor = :white # let axis labels be seen on dark background
 scene

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 9, 2019, 1:38pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/2 "2019-08-09T13:38:27Z")

</div>

Not Makie, but good for now.

```julia
using PlotlyJS
function cube_form(center = 0.0)
     mesh3d(
        x=[0, 0, 1, 1, 0, 0, 1, 1],
        y=[0, 1, 1, 0, 0, 1, 1, 0] .+ center,
        z=[0, 0, 0, 0, 1, 1, 1, 1],
        i=[7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],
        j=[3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
        k=[0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
        intensity=range(0, stop=1, length=8),
        colorscale=[
            [0, "gold"],
            [0.5, "mediumturquoise"],
            [1, "gold"]
        ],
    showscale=false,
    opacity = 0.5
    )
end

t = cube_form()
t1 = cube_form(1.5)
t2 = cube_form(3.0)
plot([t, t1, t2])

```

 ![cubes](https://global.discourse-cdn.com/julialang/original/3X/9/a/9a6e17576b345474424953e52ccfff8187d1d319.jpeg)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [August 19, 2019, 10:30am UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/3 "2019-08-19T10:30:11Z")

</div>

In Makie you can do:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/3/a31fb704f3261de1d4e825672302fa85ac38ff1e.jpeg)

```julia

using Makie
function cube_form(center = 0.0)
    # In theory mesh(cube) just works, but somehow doesn't play nicely with
    # the colormap
    cube = FRect3D(Vec3f0(0) .+ Vec3f0(0, center, 0), Vec3f0(1))
    points = decompose(Point3f0, cube)
    faces = decompose(GLTriangle, cube)
    mesh!(
        points, faces,
        color = LinRange(0, 1, 8),
        colormap = [
            (:gold, 0.5),
            (:mediumturquoise, 0.5),
            (:gold, 0.5)
        ],
        transparency = true
    )
end
s = Scene()
t = cube_form()
t1 = cube_form(1.5)
t2 = cube_form(3.0)
s

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 19, 2019, 12:34pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/4 "2019-08-19T12:34:10Z")

</div>

I got the following error in julia 1.0.3 ?

UndefVarError: GLTriangle not defined

Stacktrace:  
[1] cube\_form(::Float64) at ./In[1]:8  
[2] cube\_form() at ./In[1]:6  
[3] top-level scope at In[1]:21

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [August 19, 2019, 12:34pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/5 "2019-08-19T12:34:32Z")

</div>

Sorry, needs a `using GeometryTypes`

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 19, 2019, 12:38pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/6 "2019-08-19T12:38:36Z")

</div>

Now it works.  
How did you change the angle of projection (view angle)? My output doesn’t look like yours.

Edit: Oh, the output in a jupyter notebook is fixed. But running just the script pops out a window where rotation is posible.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [August 19, 2019, 1:39pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/7 "2019-08-19T13:39:52Z")

</div>

You can have the same effect inside a notebook with:

```julia
AbstractPlotting.inline!(false)

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 19, 2019, 1:48pm UTC](https://discourse.julialang.org/t/array-of-boxes-using-makie-and-volume/27350/8 "2019-08-19T13:48:54Z")

</div>

```julia
AbstractPlotting.inline!(false)

```

Not working in my end. And no error is shown. Dead end here 😄
