如何将二维图添加到三维轴图?

如何将二维图添加到三维轴图?

我的任务很简单。我想在 3D 轴上添加一个 2D 图。我的最终结果是这样的:

\begin{tikzpicture}
    \begin{axis}[
            axis equal,
            view={45}{30},
            compat=1.8,
            height=10.2cm,
            width=9cm,
            grid=major,
            grid style={dashed, gray!50},
            axis lines=middle,
            inner axis line style={=>},
            yticklabel style={inner ysep=0pt, anchor=south east, font=\tiny},
            ytick={-1,...,1},
            xticklabel style={inner xsep=0pt, anchor=north west, font=\tiny},
            xtick={-1,...,1},
            zticklabel style={inner ysep=0pt, anchor=south east, font=\tiny},
            ztick={-1,...,1},
            ymin=-2,
            ymax=2,
            xmin=-2,
            xmax=2,
            zmin=-2,
            zmax=2]
        \addplot+[color=PlotColorOne, samples=30, domain=0:2*pi, thick, smooth, z=0] ({sin(deg(x))},{cos(deg(x))});
    \end{axis}
\end{tikzpicture}

结果是:

输出

如何将 z 坐标设置为 0?

答案1

您可以将所需的二维图视为三维图z=0。因此使用

\addplot3 ({sin(deg(x))},{cos(deg(x))},0)`

你得到:

在此处输入图片描述

代码:

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            axis equal,
            view={45}{30},
            compat=1.8,
            height=10.2cm,
            width=9cm,
            grid=major,
            grid style={dashed, gray!50},
            axis lines=middle,
            inner axis line style={=>},
            yticklabel style={inner ysep=0pt, anchor=south east, font=\tiny},
            ytick={-1,...,1},
            xticklabel style={inner xsep=0pt, anchor=north west, font=\tiny},
            xtick={-1,...,1},
            zticklabel style={inner ysep=0pt, anchor=south east, font=\tiny},
            ztick={-1,...,1},
            ymin=-2,
            ymax=2,
            xmin=-2,
            xmax=2,
            zmin=-2,
            zmax=2]
        \addplot3[color=red, samples=30, domain=0:2*pi, thick, smooth, z=0] ({sin(deg(x))},{cos(deg(x))},0);
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容