# 3D plotting packages

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.

``````[
[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!

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.

1 Like

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

``````[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!

Take a look at MeshViz.jl, the command

``````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.

2 Likes

I think you’re looking for something like this:

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

3 Likes

Yeah, somewhat like this.

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

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

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

There you can find the meaning of MWE.

This works for me:

``````using Meshes
using MeshViz
using Colors

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

1 Like

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.

1 Like

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!

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

1 Like

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

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

1 Like

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

Now I have it.

1 Like

How’s this one:

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

3 Likes

Another way, using Colors and PlotlyJS:

Code
``````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)
``````
4 Likes

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

3 Likes