How to Create a Ring Torus with Plots? (I have the code with GLMakie and gnuplot package that need more perfectioning)

Hi all,

I want to create 3-dimensional torus like this:

Capture d’écran_2022-12-25_16-55-09

With GLMakie or Plots, because I want to add annotations, and then I can see which is x,y,z axis

I get the code from Lazarus’ website

using Gnuplot
    U  = LinRange(-π,π, 50)
    V = LinRange(-π,π, 30)
    r = 0.5
    x = [1 + cos(u) + r * cos(u) * cos(v)  for u in U, v in V]
    y = [r * sin(v)                        for u in U, v in V]
    z = [sin(u) + r * sin(u) * cos(v)      for u in U, v in V]
    @gsp "set pm3d depthorder"
    @gsp :- "set style fill transparent solid 0.5"
    @gsp :- "set pm3d lighting primary 0.05 specular 0.2"
    @gsp :- x y z "w l palette notit" palette(:dense) "set view 108,2"
    @gsp :- "unset border" "set xyplane 0"
    @gsp :- "unset tics"
    @gsp :- "unset colorbox"

with gnuplot it has a lot of lines, maybe because my eyes are used to Plots and gr().

Capture d’écran_2022-12-25_16-56-24

I have more questions about 3-d plots in the future. Thanks for all your help here.


I have the GLMakie code thanks to this topic:

My question on this GLMakie, how to add the label to x,y,z axis?

using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
	cmap4 = [(cmap3[i],0.65) for i in 1:100]
	ξ = -40:1:40
	c = 20
	a = 15
	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)

why GLMakie plot of torus has a glitch? like small black hole around the torus?

With Plots.jl, the plotlyjs() backend provides good results:

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


1 Like

PlotlyJS is absolutely amazing and better than GLMakie in my opinion