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

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

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:

1 Like

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.

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

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

N = 50  # "resolution"

# cartesian coordinates
ϕ = 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
θ = 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])


1 Like

Thanks a lot @mbaz
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)))


set xtics font “, 30”

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

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

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.

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