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

**URL:** https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105
**Category:** General Usage
**Tags:** question
**Created:** [December 25, 2022, 11:13am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105 "2022-12-25T11:13:47Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 25, 2022, 11:13am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/1 "2022-12-25T11:13:47Z")

</div>

Hi all,

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

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

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

 ![Capture d’écran_2022-12-25_18-10-08](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed051df0a8931aca6cae59534c65f1fb294a9318.png)

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

---

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [December 25, 2022, 11:22am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/2 "2022-12-25T11:22:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 25, 2022, 12:25pm UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/3 "2022-12-25T12:25:25Z")

</div>

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

It is a criteria right?

---

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [December 25, 2022, 12:32pm UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/4 "2022-12-25T12:32:36Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> 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](http://beautiful.makie.org).

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 25, 2022, 12:43pm UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/5 "2022-12-25T12:43:16Z")

</div>

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

> **[Meshes: Cylinder, Pyramid, Sphere, Rect3 - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/meshes/meshes/)**
>
> Makie Examples

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 25, 2022, 12:58pm UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/6 "2022-12-25T12:58:22Z")

</div>

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

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

![Capture d’écran_2022-12-25_19-58-00](https://global.discourse-cdn.com/julialang/original/3X/e/b/eba30bd53f1339dbd3de6ca4abb246c80d81dace.png)

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [December 29, 2022, 6:57am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/7 "2022-12-29T06:57:23Z")

</div>

Can the default GR backend produce similar surface plots?

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 29, 2022, 7:15am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/8 "2022-12-29T07:15:29Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> ```julia
> 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, )
> 
> ```

Different with GR

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

```

![Capture d’écran_2022-12-29_14-14-58](https://global.discourse-cdn.com/julialang/original/3X/e/c/ecc4d47b465de7c491695b87cb2a6510ea24924a.png)

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [December 29, 2022, 7:48am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/9 "2022-12-29T07:48:06Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [December 29, 2022, 7:50am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/10 "2022-12-29T07:50:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 29, 2022, 8:07am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/11 "2022-12-29T08:07:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [December 29, 2022, 8:26am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/12 "2022-12-29T08:26:12Z")

</div>

I seem to find an answer:

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

 ![图片](https://global.discourse-cdn.com/julialang/original/3X/3/9/39df9142fef519c365a36bbf190ec5a793a272ae.png)

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 29, 2022, 9:50am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/13 "2022-12-29T09:50:07Z")

</div>

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.

---

<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: [December 29, 2022, 10:56am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/14 "2022-12-29T10:56:07Z")

</div>

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

[GLMakie](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/torus/)

[Gnuplot 2](https://lazarusa.github.io/gnuplot-examples/dev/examples/generated/3d/surfaces/torus_depth_sorting/)

[Gnuplot 1](https://lazarusa.github.io/gnuplot-examples/dev/examples/generated/3d/surfaces/torus/)

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [December 29, 2022, 11:20am UTC](https://discourse.julialang.org/t/why-plotlyjs-is-better-than-glmakie-in-creating-torus-3-dimensional-object/92105/15 "2022-12-29T11:20:35Z")

</div>

Computer art is amazing!
