Unable to plot a sphere surface using Plots package

Just for the record, a decent sphere can be produced with Plots.jl gr() back-end by splitting it in two (top and bottom surfaces). However, it requires a careful computation of the end points for a nice stitching job and minding the plotting order.

using Plots; gr()

zplus(x,y) = (x^2 + y^2) <= 1 ? sqrt.(abs.(1.0 .- x.^2 .- y.^2)) : NaN
zminus(x,y) = (x^2 + y^2) <= 1 ? -sqrt.(abs.(1.0 .- x.^2 .- y.^2)) : NaN

x = collect(-1:0.01:1);
y = @. (1-x^2)^0.5
y = reshape(permutedims([-y y]),:,1)[:]
x = sort([x; x.+eps()])

surface(x,y,zminus, ratio=:equal,xlims=(-1,1),ylims=(-1,1),zlims=(-1,1))  # isometric
surface!(x,y,zplus, ratio=:equal,xlims=(-1,1),ylims=(-1,1),zlims=(-1,1))  # isometric

Plots_gr_sphere_2_halves

1 Like