# How to make a 3d sphere in Gaston USING THE SET MAPPING SPHERICAL OPTION?

**URL:** <https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848>\
**Category:** Visualization\
**Tags:** plotting, gaston\
**Created:** [October 22, 2020, 9:41pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848 "2020-10-22T21:41:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [October 22, 2020, 9:41pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/1 "2020-10-22T21:41:30Z")

</div>

set mapping spherical can be enabled using,  
surf(x,y,z, Axes(mapping=“spherical”))

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [October 23, 2020, 1:06am UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/2 "2020-10-23T01:06:31Z")

</div>

Could you please clarify what the problem is? What data are you plotting, and what do you expect to get?

By the way, plotting spheres is easy enough without resorting to spherical coordinates: [3-D Plots · Gaston.jl](https://mbaz.github.io/Gaston.jl/stable/3d-gallery/#Spheres-1)

---

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [October 23, 2020, 12:54pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/3 "2020-10-23T12:54:17Z")

</div>

Yeah well… I’ve to plot vectors on it… and I already have θ and ɸ, where r is the radius of the sphere as polar co-ordinates, the vectors will be from 0 0 0 to θ, ɸ and r polar co-ordinates

P(x, y, z) is the point in cartesian co-ordinate system. O is the origin(0,0,0)  
ɸ is the angle from (0, 0) to the projection (x₀ , y₀ ) of P into the xy plane.  
θ is the angle from the positive zaxis to the line segment OP.

---

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [October 23, 2020, 12:55pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/4 "2020-10-23T12:55:33Z")

</div>

I’m uncomfortable with the set mapping option too… Any way I can convert the above data into 3d cartesian co-ordinates?

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [October 23, 2020, 3:13pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/5 "2020-10-23T15:13:37Z")

</div>

For completeness, here’s an example drawing spheres in cartesian and spherical coordinates.

```julia
N = 50 # "resolution"

# cartesian coordinates
figure(1)
ϕ = LinRange(0, 2pi, N); # latitude of each equator (parallel)
θ = LinRange(-pi, pi, N); # draw equators from pole to pole
x = [cos(r)*cos(a) for r in θ, a in ϕ]
y = [cos(r)*sin(a) for r in θ, a in ϕ]
z = [sin(r) for r in θ, _ in ϕ]
f1 = surf(x, y, z,
          Axes(view = "equal xyz",
               hidden3d = :on,
               pm3d = "depthorder",
               palette = :summer,
               title = "'Cartesian'",
               tics = -1:0.5:1
              ),
          w = "pm3d"
         );

# spherical coordinates
figure(2)
θ = LinRange(0, 2pi, N) # azimuth angle (longitude)
ϕ = LinRange(-pi, pi, N) # polar angle (latitude)
lon = [l for l in θ, _ in ϕ]
lat = [l for _ in θ, l in ϕ]
rad = [1 for _ in θ, l in ϕ] # constant radius = 1
f2 = surf(lon, lat, rad,
          Axes(mapping = "spherical",
               view = "equal xyz",
               hidden3d = :on,
               pm3d = "depthorder",
               palette = :ice,
               title = "'Spherical'",
               tics = -1:0.5:1
              ),
          w = "pm3d"
        );
plot([f1 f2])

```

![image](https://global.discourse-cdn.com/julialang/original/3X/6/a/6a5321c6a96bd0eecbef9a90bd898a087f03437c.png)

---

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [November 14, 2020, 1:19pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/6 "2020-11-14T13:19:33Z")

</div>

Thanks a lot @mbaz  
Also,  
In Gaston, is there any way to change the size of xtics?  
For example, what should I add to this to change the size?  
Axes(xtics = (0:7, string.(0:7, base=2, pad=3)))

---

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [November 14, 2020, 1:28pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/7 "2020-11-14T13:28:24Z")

</div>

Apparently,

set xtics font “, 30”

is an option, but I can’t get it to work with the above syntax, any help is appreciated!

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 14, 2020, 6:13pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/8 "2020-11-14T18:13:54Z")

</div>

Just do `Axes(xtics = "font ',30'")`.

---

<div class="post-metadata">

**Author:** ![ChetanVardhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chetanvardhan/32/222198_2.png) [@ChetanVardhan](https://discourse.julialang.org/u/ChetanVardhan)\
**Post date:** [November 15, 2020, 5:02pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/9 "2020-11-15T17:02:22Z")

</div>

It doesn’t work with  
` Axes(xtics = (0:7, string.(0:7, base=2, pad=3)))`  
I strictly need the tics to be displayed in binary form.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 15, 2020, 8:02pm UTC](https://discourse.julialang.org/t/how-to-make-a-3d-sphere-in-gaston-using-the-set-mapping-spherical-option/48848/10 "2020-11-15T20:02:45Z")

</div>

Gaston’s helper syntax does not support combining a range with a font specification. The solution is to build a gnuplot command explicitly:

```
T = join(["'$(string(D, base=2, pad=3))' $D" for D in 0:7], ",")
xt = "($T) font ',30'"
plot(0:7, (0:7).^2, Axes(xtics=xt))

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/4/449a24a9a1bc35b5b9e5a8ac4e3f8f298504ddf8.png)
