How do I draw a grayscale shaded sphere with tikz-3dplot? I tried using \tdplotsphericalsurfaceplot with radius equal to 1, and parametricfill depending on the spherical angles. However, it looks like I can only prescribe the color's hue (in HSB space), according to the following post, which does not suit me. I could go all the way and redefine \tdplotdosurfaceplot, but that seems overkill.

Let me emphasize that I want true 3D drawing (the rest of my picture requires 3D coordinates: I need to draw arcs), so I cannot use 2D tricks such as

\draw [ball color=white] (0,0,0) circle (1) ;

so this is not a duplicate of how-to-draw-a-shaded-sphere. I explicitly want a 3d drawing, preferably with tikz-3dplot, though I'm open to other 3d packages.

Here are two MWEs: the first sphere uses uniform coloring, while the second uses a linear combination of the spherical angles:

\tdplotsphericalsurfaceplot[parametricfill]{24}{24}{1} {black}{50}{}{}{}
\tdplotsphericalsurfaceplot[parametricfill]{24}{24}{1} {black}{\tdplottheta+\tdplotphi}{}{}{}

I would also like to get rid of the parametric lines... Maybe this is not the right package to work with, or the right command in the package. enter image description here

  • pgfplots grant you full access by default. Keywords: surf and point meta – Symbol 1 Jul 13 '17 at 1:23
  • If you want 'true 3D', PGF/TikZ is not the package to choose. You can use it to fake 3D in 2D, but it does not do real 3D at all. tikz-3dplot helps do calculations required to fake 3D in 2D. – cfr Jul 17 '17 at 15:28
  • @cfr I'll be happy to know other options. My goal is to draw a circular arc on the sphere, given 3d coordinates of its endpoints. – Pascal Romon Jul 18 '17 at 12:48
  • Thanks to all answers, I can now rephrase my question: I want to draw circular arcs on a gray shaded sphere, with actual 3d coordinates of the spherical points. tikz-3dplot is reasonably good at drawing circular arcs, but poor at shading the sphere. pgfplots excels at drawing graphs, including the sphere, but afaik does not know how to draw circular arcs (or in a very complicated way). Moreover the two do not work well together. Any idea of a package that would allow me to reach both? – Pascal Romon Jul 23 '17 at 18:30

Better use pgfplots (adapted from this post). The parametric fill with \theta+\phi looks pretty weird in my opinion.

      axis equal,enlargelimits=false,
      axis lines=none,
      y domain=0:360,samples y=21,
        z buffer=sort,
        point meta={acos(z/sqrt(x*x+y*y+z*z)) + atan2(y,x)}
      ] (

enter image description here

  • Thanks @henri-menke. Happy to learn about this package. It does what I wanted, especially with the shader=interp option. However, it does no play so well with the rest of my code in tikz-3dplot. The reason being (I suppose) that the axis environment defines its own 3d coordinates; hence any subsequent 3d instruction is drawn w.r.t. another one. I'll have to look it up. Btw, the choice of shading function \theta+\phi was just an example, not the real thing. – Pascal Romon Jul 18 '17 at 12:46
  • My mistake: I only need to write the rest of the 3d code within the axis environment. – Pascal Romon Jul 18 '17 at 13:14

After trying bits here and there, I have come up with an acceptable solution, which does use tikz-3dplot (with shortcomings, see below). Here's a MWE, showing a spherical triangle drawn on the shaded sphere. For different shadings, simply go to how-to-draw-a-shaded-sphere.

The solution below cheats partially: it does not draw a shaded sphere but rather a shaded 2D disc in perspective; therefore one has to rotate it in 3-space to make it appear like a sphere (hence the rotated coordinates). However the spherical coordinates of the arcs are true.


    % spherical background
    \draw [ball color=white,very thin,tdplot_rotated_coords] (0,0,0) circle (1) ;
    % equator
    \draw [dashed] (0,0,0) circle (1) ;
    % spherical triangle

Another shortcoming is the awkward syntax in tikz-3dplot for defining arcs, and the fact that you cannot mix it with the coordinate command. spherical triangle on shaded sphere

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.