# Why PlotlyJS is Better than GLMakie in Creating Torus 3-dimensional object?

Hi all,

Thanks from the help of people in this discourse, I have plotted with GLMakie with this code:

``````using GLMakie
using ColorSchemes
# Torus equation to plot
# R - sqrt(x^2 + y^2) + z^2 = r^2
# r -> a (r is the radius of the smaller circle / innertube)
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
cmap4 = [(cmap3[i],0.65) for i in 1:100]
ξ = -50:1:50
c = 25
a = 5
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
volume(torus, algorithm = :iso,isovalue =100,isorange =50, colormap=cmap4)
current_figure()
``````

and with PlotlyJS

``````using Plots; plotlyjs()

Θ = ϕ = range(-π,π,300)
X = [(2 + cos(v)) * cos(u) for u in Θ, v in ϕ]
Y = [(2 + cos(v)) * sin(u) for u in Θ, v in ϕ]
Z = [1.5*sin(v) for u in Θ, v in ϕ]
surface(X, Y, Z, lims=(-3,3), size=(600,600), cbar=:none, legend=false, )
``````

why is the plot of PlotlyJS is better? They are showing the x,y,z axis as well when I point at the torus.Anyone who opposes PlotlyJS and want to brag about GLMakie are welcome to convince me about GLMakie.

PlotlyJS left, GLMakie right.

I want to plot a lot of 3-d objects and perhaps I want to fix with PlotlyJS backend to be more focus.

1 Like

I am neither opposing PlotlyJS nor am I bragging about GLMakie, but by what criteria do you think PlotlyJS is better than GLMakie?

4 Likes

By the plot of the torus I showed at my above post.

It is a criteria right?

I would argue that this is subjective to your taste, though, I have to agree that the grey axes on black background don’t look so nice.

But Makie offers various theming options. You might want to take a look at beautiful.makie.org.

3 Likes

Maybe it is why I need to see your post, thus able to see this:

This is nice, I just try to create a blue torus with GLMakie, a great result. Thanks!!!

``````using GLMakie
GLMakie.activate!()
set_theme!(backgroundcolor = :white)

Θ = ϕ = range(-π,π,300)
x = [(2 + cos(v)) * cos(u) for u in Θ, v in ϕ]
y = [(2 + cos(v)) * sin(u) for u in Θ, v in ϕ]
z = [1.5*sin(v) for u in Θ, v in ϕ]
fig = surface(x, y, z, colormap = [:dodgerblue],
lightposition = Vec3f(0, 0, 0.8), ambient = Vec3f(0.6, 0.6, 0.6),
backlight = 2.0f0)
#wireframe!(x, y, z; overdraw = false, linewidth = 0.1) # try overdraw = true
fig

``````

Anyone wants a blue doughnut? 3 Likes

Can the default GR backend produce similar surface plots?

Different with GR

``````using Plots; gr()

Θ = ϕ = range(-π,π,300)
X = [(2 + cos(v)) * cos(u) for u in Θ, v in ϕ]
Y = [(2 + cos(v)) * sin(u) for u in Θ, v in ϕ]
Z = [1.5*sin(v) for u in Θ, v in ϕ]
surface(X, Y, Z, lims=(-3,3), size=(600,600), cbar=:none, legend=false, )

`````` 2 Likes

Thanks a lot. Actually what I really want to ask is how to assign a color (gradient) as a given function of points to each point on the surface?

1 Like

For example, if I want to visualize the diffusion process on a sphere?

1 Like

Great question, unfortunately, I haven’t reach that stage yet and unable to answer, perhaps @rafael.guerra or @nilshg can help you.

1 Like

I seem to find an answer:

``````using Plots

p = 100
Θ = (π*i/p for i = 0:p)
ϕ = (2π*i/p for i = 0:p)
X = [cos(v) * sin(u) for u in Θ, v in ϕ]
Y = [sin(v) * sin(u) for u in Θ, v in ϕ]
Z = [cos(u) for u in Θ, v in ϕ]
c=[RGBA(0.5*cos(u)+0.5,0,0.5*sin(v)+0.5,0) for u in Θ, v in ϕ]
surface(X, Y, Z, lims=(-1.5,1.5), size=(600,600), c=c, cbar=:none)
``````

gives

1 Like

Wow great!

I was thinking you want to plot a data from DataFrames and then plot the data into 3-d surface with gradient coloring.

I like all my torus. They could be as much as twins, but I prefer some diversity GLMakie

Gnuplot 2

Gnuplot 1

3 Likes

Computer art is amazing!

1 Like