我正在绘制参数函数并获取它们的不同视图。问题在于顶视图,特别是当函数在 z 方向上变化时,透视不正确。代码示例和图像
\documentclass[varwidth ,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{tikz,pgfplots,tikz-3dplot}
%\pgfplotsset{compat=1.12}
%\pgfplotsset{,compat=1.17}
%\pgfplotsset{compat=newest}
\begin{document}
%
\begin{tikzpicture}
\begin{axis}[
view={-45}{45},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
]
\addplot3 [surf] {x};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
xlabel=$x$,
ylabel=$y$,
]
\addplot3 [surf] {x+y};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3[
domain=0:5*pi,
samples=201,
samples y=1, ](
{sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture} \begin{axis}[view={0}{90}]
\addplot3[
domain=0:5*pi,
samples=201,
samples y=1, ](
{sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture} [trig format=rad ]
\begin{axis}[view={60}{-40}]]
\addplot3 [surf, variable=t,
domain=0:5*pi,
samples=501,
samples y=1](
{0.5*t*cos(10*t)},
{0.5*t*sin(10*t)},
{pi-1*t}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture} [trig format=rad ]
\begin{axis}[view={0}{90}]
\addplot3 [surf, variable=t,
domain=0:5*pi,
samples=501,
samples y=1](
{0.5*t*cos(10*t)},
{0.5*t*sin(10*t)},
{pi-0.5*t}
);
\end{axis}
\end{tikzpicture}
%
\end{document}
答案1
主要问题是您使用了trig format=rad
。pgfplots
使用三角函数来安装视图,然后您“搞砸了它们”(这并不是故意冒犯)。这就是为什么pgfplots
有一个选项trig format plots=rad
。其他影响部分是因为您更改了函数,例如{x}
转到{x+y}
。
\documentclass[varwidth ,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{tikz,pgfplots,tikz-3dplot}
%\pgfplotsset{compat=1.12}
\pgfplotsset{compat=1.17}
%\pgfplotsset{compat=newest}
\begin{document}
%
\begin{tikzpicture}
\begin{axis}[
view={-45}{45},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
]
\addplot3 [surf] {x};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
xlabel=$x$,
ylabel=$y$,
]
\addplot3 [surf] {x+y};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3[
domain=0:5*pi,
samples=201,
samples y=1, ](
{sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3[
domain=0:5*pi,
samples=201,
samples y=1, ](
{sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}% [trig format=rad ]
\begin{axis}[view={60}{-40},trig format plots=rad]
\addplot3 [surf, variable=t,
domain=0:5*pi,
samples=501,
samples y=1](
{0.5*t*cos(10*t)},
{0.5*t*sin(10*t)},
{pi-1*t}
);
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}%[trig format=rad]
\begin{axis}[view={0}{90},trig format plots=rad]
\addplot3 [mesh, variable=t,
domain=0:5*pi,
samples=501,
samples y=0,
mesh/ordering=y varies,
%z buffer=sort
](
{0.5*t*cos(10*t)},
{0.5*t*sin(10*t)},
{pi-0.5*t}
);
\end{axis}
\end{tikzpicture}
%
\end{document}