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

**URL:** <https://discourse.julialang.org/t/how-to-create-a-ring-torus-with-plots-i-have-the-code-with-glmakie-and-gnuplot-package-that-need-more-perfectioning/92103>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 25, 2022, 9:57am UTC](https://discourse.julialang.org/t/how-to-create-a-ring-torus-with-plots-i-have-the-code-with-glmakie-and-gnuplot-package-that-need-more-perfectioning/92103 "2022-12-25T09:57:47Z")\
**Posts on this page:** 3\
**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, 9:57am UTC](https://discourse.julialang.org/t/how-to-create-a-ring-torus-with-plots-i-have-the-code-with-glmakie-and-gnuplot-package-that-need-more-perfectioning/92103/1 "2022-12-25T09:57:47Z")

</div>

Hi all,

I want to create 3-dimensional torus like this:

![Capture d’écran_2022-12-25_16-55-09](https://global.discourse-cdn.com/julialang/original/3X/a/0/a03aa9fd12ea089d7b03192dc632cc8083ef340a.png)

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

```julia
using Gnuplot
let
    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"
end

```

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](https://global.discourse-cdn.com/julialang/original/3X/4/4/449860247685344e7fe6314435c6aff646d809b4.png)

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

Edited:

I have the GLMakie code thanks to this topic:

> [@Makie isosurface transparency?](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/12):
>
> Ok, getting closer. Still puzzling: I make a torus geometry. Why isn’t the full torus visible even though there is an alpha? It seems that the alpha is applied to another surface (dual ellipsoid case above), but not to different parts of the same surface. We should be able to see the core of the torus, and the back surface: 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 = [((h…

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

```julia
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)
	current_figure()

```

 ![Capture d’écran_2022-12-25_16-59-35](https://global.discourse-cdn.com/julialang/original/3X/2/2/227b1a71c5769373c35977d5fa04580dba8f8a9f.png)

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

---

<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:** [December 25, 2022, 10:52am UTC](https://discourse.julialang.org/t/how-to-create-a-ring-torus-with-plots-i-have-the-code-with-glmakie-and-gnuplot-package-that-need-more-perfectioning/92103/2 "2022-12-25T10:52:26Z")

</div>

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

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

```

![Plots_plotlyjs_torus_parametric_surface](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6d2f5c5f54e1bafab331f9073093fcee49fcc6c.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 25, 2022, 11:04am UTC](https://discourse.julialang.org/t/how-to-create-a-ring-torus-with-plots-i-have-the-code-with-glmakie-and-gnuplot-package-that-need-more-perfectioning/92103/3 "2022-12-25T11:04:52Z")

</div>

PlotlyJS is absolutely amazing and better than GLMakie in my opinion
