我想知道如何在 中创建多个参数pgfplot
?在代码中,我使用x
和y
作为参数来绘制球体,使用radiuse 1cm
。当我添加x=2cm
、y=2cm
、z=2cm
时,绘图会更好看:
\documentclass{book}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1,font=\tiny]
\begin{axis}[
axis x line=middle,
axis y line=middle,
axis z line=middle,
colormap/jet,
samples=40,
view={130}{30},
domain=-4:4,
y domain=-4:4,
restrict z to domain=-4:4,
grid=both,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmax=2,
ymax=2,
zmax=2,
xmin=-2,
ymin=-2,
zmin=-2,
xtick={-10,...,10},
ytick={-10,...,10},
ztick={-10,...,10},
x=2cm,
y=2cm,
z=2cm,
every axis x label/.style={
at={(ticklabel* cs:1)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,},
every axis z label/.style={
at={(ticklabel* cs:1)},
anchor=west,}
]
\addplot3 [
samples=30,
domain=0:2*pi,
y domain=0:2*pi,
]
({cos(y*180/pi)*cos(x*180/pi)},
{cos(y*180/pi)*sin(x*180/pi)}, {sin(y*180/pi)});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
不幸的是,当我添加它们时,view
功能停止工作。如何修复该问题并仅在XY
纯文本中绘制网格?
答案1
pgfplots
手册上有这个警告!
对于三维轴,pgfplots 根据提供的单位向量计算视图方向。视图方向是允许 z 缓冲功能(即决定深度)所必需的
在第 241 页,版本 1.11 的第 4.10 节。因此,当您悬挂轴单位时,它将改变视角。
如果想法是扩大,则可以使用scale
键。
\documentclass{book}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1,font=\tiny]
\begin{axis}[
%x post scale=2,
% y post scale=2,
% z post scale=2,
scale=2,
axis x line=middle,
axis y line=middle,
axis z line=middle,
colormap/jet,
samples=40,
view={130}{30},
domain=-4:4,
y domain=-4:4,
restrict z to domain=-4:4,
grid=both,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
xmax=2,
ymax=2,
zmax=2,
xmin=-2,
ymin=-2,
zmin=-2,
xtick={-10,...,10},
ytick={-10,...,10},
ztick={-10,...,10},
every axis x label/.style={
at={(ticklabel* cs:1)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,},
every axis z label/.style={
at={(ticklabel* cs:1)},
anchor=west,}
]
\addplot3 [
samples=30,
domain=0:2*pi,
y domain=0:2*pi,
]
({cos(y*180/pi)*cos(x*180/pi)},
{cos(y*180/pi)*sin(x*180/pi)}, {sin(y*180/pi)});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}