13

I am trying to draw a solid sphere with a cylindrical drilled through its center. The best I have been able to do is:

enter image description here

which does not show it is solid. How do I make it more solid in appearance?

Notes:

  • The code is adapted from Strange problems in 3D-Plots TikZ: Missing parts and axes
  • Besides a nice color version, I also need to be able to copy this in black and white so if you have suggestions on that, that would be helpful as well.
  • Eventually need to be able to label the two radii: the sphere's and the cylinder's.

Code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document} \begin{tikzpicture} \begin{axis}[width=\textwidth, samples=25,domain=0:360,y domain=-60:60, xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2,zmin=-1.2,zmax=1.2, xlabel={$x$},ylabel={$y$},zlabel={$z$}, axis lines=none] \addplot3[surf,opacity=0.5] ({cos(x)cos(y)}, {sin(x)cos(y)}, {1.5*sin(y)}); \end{axis} \end{tikzpicture} \end{document}

Peter Grill
  • 223,288

1 Answers1

8

I found the colormap/blackwhite paprameter for axis environment from PGF manual and shader option.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=\textwidth,
  samples=25,domain=0:360,y domain=-60:60,
  xmin=-1.2,xmax=1.2,ymin=-1.2,ymax=1.2,zmin=-1.2,zmax=1.2,
  xlabel={$x$},ylabel={$y$},zlabel={$z$},
  axis lines=none,
  colormap/blackwhite]
\addplot3[surf,opacity=0.5,shader=interp]
  ({cos(x)*cos(y)}, {sin(x)*cos(y)}, {1.5*sin(y)});
\end{axis}
\fill[top color=white,bottom color=blue!10,middle color=gray,shading=axis,opacity=0.25] (5.25,2) circle (1.75cm and 0.6cm);% Bottom hole
\end{tikzpicture}
\end{document}

Here is the result:

enter image description here

Update: For adding bottom hole, insert some code using circle.

enter image description here

  • That certainly helps with the black and white print version issue, but still does not quite look solid -- still appears to be just a shell of a sphere. – Peter Grill Feb 21 '14 at 22:17