# [Tex/LaTex] Draw sphere pgfplots with axis at center

pgfplotstikz-pgf

I want to draw a plot that illustrates the ration pattern of an isotropic antenna. I thought about pgfplots to do the job. I grabbed the code from pgfplots manual and did some changes; but it doesn't satisfies me.

As I said in the title, I want the axis to be drawn in the center, but I also want to be able to see the (0,0,0) point. So to be able to look inside, the sphere surface opacity shall be lower.

Moreover, the code is not optimized, I need to specify the min and max for all axis just to see the arrow of the axis outside the surface. Is there a better way?

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{%
compat=1.8,
compat/show suggested version=false,
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
footnotesize,
axis equal,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
xmax=2,xmin=-2,
ymax=2,ymin=-2,
zmax=2,zmin=-2,
xtick=\empty,
ytick=\empty,
ztick=\empty,
]
surf,
z buffer=sort,
samples=15,
variable=\u,
variable y=\v,
domain=0:180,
y domain=0:360
]
({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
\end{axis}
\end{tikzpicture}

\end{document}


Using axis equal causes to maintain the width/height and to modify axis limits and the image scaling. In order to keep the axis limits and modify just the units, we can say scale uniformly strategy=units only. I added width=10cm to enlarge the sphere compared to the axis descriptions (different fonts for the axis description might also have done the job). Adding height=10cm as well avoids confusion as to which of the parameters width or height is to be used in the final version.

Adding view/h=45 appears to be quite good as well.

Combined with opacity as suggested by Henri, we end up at \documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis equal,
width=10cm,
height=10cm,
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
ticks=none,
enlargelimits=0.3,
view/h=45,
scale uniformly strategy=units only,
]
opacity = 0.5,
surf,
z buffer = sort,
samples = 21,
variable = \u,
variable y = \v,
domain = 0:180,
y domain = 0:360,
]
({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
\end{axis}
\end{tikzpicture}
\end{document}


We can also change the parameterization of the sphere to screen coordinate rather than angles and get the LEFT image (the right is the same as above)  \documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis equal,
width=10cm,
height=10cm,
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
ticks=none,
enlargelimits=0.3,
view/h=45,
scale uniformly strategy=units only,
]
surf,
opacity = 0.5,
samples=21,
domain=-1:1,y domain=0:2*pi,
z buffer=sort]
({sqrt(1-x^2) * cos(deg(y))},
{sqrt( 1-x^2 ) * sin(deg(y))},
x);

\end{axis}
\end{tikzpicture}

\end{document}


I causes an even distribution along the z axis (but not along the angles).