我正在尝试为 z 的正域绘制一个半球体,为负域绘制一个半椭圆体。到目前为止,我已经能够绘制每个图形,但当 z 接近零时,图形就会消失。以下是我目前所得到的:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.16}
\begindocument
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmin=-3, xmax=3,
ymin=-3, ymax=3,
zmin=-4, zmax=3,
xtick={-3,-2,-1,0,1,2,3},
ytick={-3,-2,-1,0,1,2,3},
ztick={-4,-3,-2,-1,0,1,2,3},
view={170}{10},
axis equal,
samples=60,
scale=3
]
\addplot3[surf,opacity=0.3,shader=flat,domain=0:180,y domain=0:360]
({2*sin(x)*cos(y)}, {2*sin(x)*sin(y)}, {2*((cos(x))^2)^(1/2)});
\addplot3[surf,opacity=0.3,shader=flat,domain=0:180,y domain=0:360]
({2*sin(x)*cos(y)}, {2*sin(x)*sin(y)}, {-3.5*((cos(x))^2)^(1/2)});
\end{axis}
\end{tikzpicture}
\end{figure}
答案1
您需要以这样的方式设置样本大小,即一个样本恰好位于相关轴的所需位置。在这种情况下,您应该能够使用任何奇数值作为选项来samples
获得所需的结果,例如33
或61
:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmin=-3, xmax=3,
ymin=-3, ymax=3,
zmin=-4, zmax=3,
xtick={-3,-2,-1,0,1,2,3},
ytick={-3,-2,-1,0,1,2,3},
ztick={-4,-3,-2,-1,0,1,2,3},
view={170}{10},
axis equal,
samples=33,
scale=3
]
\addplot3[surf,opacity=0.3,shader=flat,domain=0:180,y domain=0:360]
({2*sin(x)*cos(y)}, {2*sin(x)*sin(y)}, {2*((cos(x))^2)^(1/2)});
\addplot3[surf,opacity=0.3,shader=flat,domain=0:180,y domain=0:360]
({2*sin(x)*cos(y)}, {2*sin(x)*sin(y)}, {-3.5*((cos(x))^2)^(1/2)});
\end{axis}
\end{tikzpicture}
\end{document}