# 3D plotting packages

**URL:** <https://discourse.julialang.org/t/3d-plotting-packages/75445>\
**Category:** New to Julia\
**Tags:** plotting, mesh\
**Created:** [January 30, 2022, 3:17am UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445 "2022-01-30T03:17:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 3:17am UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/1 "2022-01-30T03:17:36Z")

</div>

Hello, Guys!  
I am playing with images right now.  
Is there a way I can plot a 3D image of RBG?  
There must be I think.(cuz Julia is awesome!)

I’ve tried this code to see what are the combinations.  
But I really like to see it at one glimpse in a 3D image.

```julia
[
	[RGB(i, j, 0) for i in 0:0.1:1, j in 0:0.1:1]
	[RGB(i, 0, j) for i in 0:0.1:1, j in 0:0.1:1]
	[RGB(0, i, j) for i in 0:0.1:1, j in 0:0.1:1]
]

```

Thanks! 😀

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 30, 2022, 8:00am UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/2 "2022-01-30T08:00:27Z")

</div>

Yes, you can plot 3d graphics with most of the plotting packages.

But what does it mean to plot a _color_ in 3d? I think you need to describe what you envision this will look like before anyone can help you further.

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 11:51am UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/3 "2022-01-30T11:51:42Z")

</div>

I expect to see a cubic box with all combinations of RGB.  
I just want to see it for fun.

```julia
[RGB(i, j, k) for i in 0:0.1:1, j in 0:0.1:1, k in 0:0.1:1]

```

This code create all the combinations of RGB in form of 11 \* 11 \* 11 tensors.  
If I understand it correctly, it means that there are 11 of 11 by 11 arrays.  
And all elements have unique colour.

Thanks for the comment!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:11pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/4 "2022-01-30T12:11:05Z")

</div>

Take a look at [MeshViz.jl](https://github.com/JuliaGeometry/MeshViz.jl), the command

```julia
grid = CartesianGrid(10,10,10)
color = [RGB(i,j,k) for i in 0:0.1:0.9, j in 0:0.1:0.9, k in 0:0.1:0.9]
viz(grid, color=vec(color))

```

should produce what you have in mind?

The package uses the Makie plotting library under the hood and tries to combine some of the basic Makie plot commands in a consistent way for end users.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 30, 2022, 12:17pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/5 "2022-01-30T12:17:42Z")

</div>

I think you’re looking for something like this:

 ![Screenshot 2022-01-30 at 12.16.12](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c835debba535b0c6978c8e4e65c0e799e1642ac.jpeg)

If you can rotate it, you’ll see the dark side… 🙂

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:31pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/6 "2022-01-30T12:31:40Z")

</div>

Yeah, somewhat like this. 😃

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:38pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/7 "2022-01-30T12:38:22Z")

</div>

I can’t see any color. just grid. Thanks for the comment.  
Your comment can be a hint. 🙂

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:39pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/8 "2022-01-30T12:39:03Z")

</div>

Can you please share a MWE? Also make sure you are using a recent release.

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:39pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/9 "2022-01-30T12:39:51Z")

</div>

what is the MWE? I’ll try with a recent release.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:40pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/10 "2022-01-30T12:40:50Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

There you can find the meaning of MWE.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:45pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/11 "2022-01-30T12:45:24Z")

</div>

This works for me:

```julia
using Meshes
using MeshViz
using Colors

# load a Makie backend
import GLMakie as Mke

grid = CartesianGrid(10, 10, 10)
color = [RGB(i,j,k) for i in 0:0.1:0.9, j in 0:0.1:0.9, k in 0:0.1:0.9]
viz(grid, color=vec(color)) # need to flatten colors

```

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

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:46pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/12 "2022-01-30T12:46:19Z")

</div>

You need to flatten the vector of colors currently (we will fix that) and the vector must have the same length of the number of grid cells.

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:49pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/13 "2022-01-30T12:49:21Z")

</div>

I did the smae code. and I get this one. 😆  
mixed order. but yes, this is what I was looking for. Vectorize is the key point!

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

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:50pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/14 "2022-01-30T12:50:02Z")

</div>

Are you sure you are using the exact same code and latest release? That output is very unlikely 🙂

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:51pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/15 "2022-01-30T12:51:23Z")

</div>

Oh, If I can rotate it, it would be amazing.  
Also I like to see the inside of box. or slice it.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 30, 2022, 12:52pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/16 "2022-01-30T12:52:57Z")

</div>

Yes, if you are using the GLMakie backend, you can rotate it.

For slices, you can create a meshdata object (see Meshes.jl docs) and then slice it.

Alternatively, you can take a look at Makie’s volumeslices:

[https://makie.juliaplots.org/stable/examples/plotting\_functions/volumeslices/index.html](https://makie.juliaplots.org/stable/examples/plotting_functions/volumeslices/index.html)

---

<div class="post-metadata">

**Author:** ![RickandMortyforever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickandmortyforever/32/33304_2.png) [@RickandMortyforever](https://discourse.julialang.org/u/RickandMortyforever)\
**Post date:** [January 30, 2022, 12:53pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/17 "2022-01-30T12:53:42Z")

</div>

Sorry, I didn’t notice that you changed 1.0 to 0.9. 😅

Now I have it.

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

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 30, 2022, 1:59pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/18 "2022-01-30T13:59:56Z")

</div>

How’s this one:

```julia
using Plots
plotly() # for interactivity
x = [(i, j, k) for i in 0:0.1:1 for j in 0:0.1:1 for k in 0:0.1:1]; # [(0,0,0), (0,0,0.1), ... (0, 0.1, 0), (0, 0.1, 0.1), ... (1, 1, 1)]
plot(x; st=:scatter, color=[RGB(a...) for a in x], xguide="R", yguide="G", zguide="B", label=nothing)

```

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

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 30, 2022, 8:12pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/19 "2022-01-30T20:12:26Z")

</div>

Another way, using Colors and PlotlyJS:

 ![PlotlyJS_RGB_cube_display](https://global.discourse-cdn.com/julialang/original/3X/f/8/f8e57693c4adac73588327bac362a712e917a6f2.jpeg)

> **Code**
>
> ```julia
> using Colors, PlotlyJS
> 
> # meshbox by @milesfrain, https://github.com/JuliaPlots/Plots.jl/issues/1500
> mesh_box(l,w,h,x,y,z, c) = PlotlyJS.mesh3d(
> x = [x, x+l, x, x+l, x, x+l, x, x+l],
> y = [y, y, y+w, y+w, y, y, y+w, y+w],
> z = [z, z, z, z, z+h, z+h, z+h, z+h],
> i = [0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7],
> j = [3, 3, 5, 5, 6, 6, 3, 3, 5, 5, 6, 6],
> k = [1, 2, 1, 4, 2, 4, 1, 2, 1, 4, 2, 4],
> color = c, flatshading = true
> )
> 
> Δl = 0.1
> boxes = GenericTrace{Dict{Symbol, Any}}[]
> for k in 0:Δl:1, j in 0:Δl:1, i in 0:Δl:1
> push!(boxes, mesh_box(Δl,Δl,Δl,i,j,k, RGB(i,j,k)))
> end
> 
> layout = Layout(scene = attr(xaxis_title="RED", yaxis_title="GREEN", zaxis_title="BLUE"))
> 
> PlotlyJS.plot(boxes, layout)
> 
> ```

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [January 30, 2022, 9:00pm UTC](https://discourse.julialang.org/t/3d-plotting-packages/75445/20 "2022-01-30T21:00:55Z")

</div>

I have not converted this one yet to GMT.jl but if you want to fold and put the cube on your desk.  
[https://docs.generic-mapping-tools.org/dev/gallery/ex11.html](https://docs.generic-mapping-tools.org/dev/gallery/ex11.html)

[Next page](https://discourse.julialang.org/t/3d-plotting-packages/75445.md?page=2)
