我想使用 \addplot3 绘制两个 3D 函数。两个图均在两个独立的轴环境中定义(在同一个轴内绘制它们会产生更糟糕的结果)。我想更改图的显示位置。目前,图 2 显示在图 1 的顶部(覆盖它)。我希望图 2 显示在图 1 上方。在下面的代码中,我添加了一个椭圆,其中包含我希望每个图所在的确切位置。
我尝试使用 at={(x,y)} 并将预期位置作为轴的选项,但是没有用。
\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithmic}
\usepackage{rotating}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Expected Position
\draw (3.43,2.55)[very thick] ellipse (1.02in and 0.515in);
% Plot 1
\begin{axis}[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=0,zmax=1,hide axis]
\addplot3[surf,z buffer=sort,colormap={}{rgb255(0cm)=(0,128,0); rgb255(1cm)= (255,255,0);color(2cm)=(orange)}, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
{x* sin(deg(y))},
{exp(-sqrt((x * cos(deg(y)))^2 + (x* sin(deg(y)))^2))}
);
\end{axis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Expected Position
\draw (3.43,6.0)[very thick] ellipse (1.02in and 0.515in);
% Plot 2
\begin{axis}[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=2,zmax=3,hide axis]
\addplot3[surf,z buffer=sort, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
{x* sin(deg(y))},
{-x^2+3}
);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
grouplots
当然,您可以使用分组图的环境。您可以选择水平或垂直显示,以及您想要的距离。
如果您希望plot 2
出现在上方,那么您可以在代码中首先列出它。如果您愿意,我留下了图例的命令,只需取消注释即可使用它。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{graphicx}
\usepackage{algorithmic}
\usepackage{rotating}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[%
group style={group size= 1 by 2, vertical sep=0cm,},
height=5cm,width=6.4cm,
%legend entries = {plot1,plot2}
]
% Plot 2
\nextgroupplot[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=2,zmax=3,hide axis]
\addplot3[surf,z buffer=sort, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
{x* sin(deg(y))},
{-x^2+3}
);
% Plot 1
\nextgroupplot[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=0,zmax=1,hide axis]
\addplot3[surf,z buffer=sort,colormap={}{rgb255(0cm)=(0,128,0); rgb255(1cm)= (255,255,0);color(2cm)=(orange)}, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
{x* sin(deg(y))},
{exp(-sqrt((x * cos(deg(y)))^2 + (x* sin(deg(y)))^2))}
);
\end{groupplot}
\end{tikzpicture}
\end{document}