结合addplot3连接在两个不同轴上定义的两个点

结合addplot3连接在两个不同轴上定义的两个点

我想绘制类似以下代码的内容,其中我尝试连接在两个不同轴上定义的两个不同点。我用它addplot3来绘制 3D 表面。但是,当我尝试连接这些点时,连接线显示在其他地方。坐标有问题。我很困惑。当然,如果我只使用一个轴绘制所有表面,那么就不会有问题。我使用多个轴的原因是我想mesh/interior colormap对内部使用不同的轴。如果我只使用一个轴,那么我将得到完全不同的结果。

我这里犯了什么错误?我想我对坐标有些理解不太好。

\begin{tikzpicture}[
 declare function={
f(\x,\y)=-exp(-2*(\x^4+\y^4));
}]

\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]
\addplot3[  
surf,
samples=30,
samples y=20,
] {f(\x+1,\y)+2};

\end{axis}

\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]
\addplot3[  
surf,
samples=30,
samples y=20,
] {f(\x+1,\y)-1};

\addplot3 coordinates {(1,3,1)} coordinate [alias=c2];

\end{axis}

\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]

\addplot3[
  surf,
  faceted color=blue,
  hide axis,
  fill=gray,
  samples=30,
  samples y=20,
] {-4};

\addplot3 [only marks, mark = *, mark size = 3pt, mark options={fill=red}]
coordinates {(-1,0,-4)} coordinate [alias=c1];

  \draw[thick, -stealth] (c1) -- (c2);

\end{axis}

\end{tikzpicture}

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
declare function={f(\x,\y)=-exp(-2*(\x^4+\y^4));},
]
\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]
\addplot3[  
surf,
samples=30,
samples y=20,
] {f(\x+1,\y)+2};
\end{axis}
\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]
\addplot3[  
surf,
samples=30,
samples y=20,
] {f(\x+1,\y)-1};
\addplot3 coordinates {(1,3,1)} coordinate (c2);
\coordinate (c2) at (1,3,1);
\end{axis}
\begin{axis}[
view={40}{15},
mesh/interior colormap name=viridis,
hide axis,
xmin=-6, xmax=6,
ymin=-6, ymax=6,
zmin=-6, zmax=6,
]
\addplot3[
surf,
faceted color=blue,
hide axis,
fill=gray,
samples=30,
samples y=20,
] {-4};
\addplot3 [only marks, mark = *, mark size = 3pt, mark options={fill=red}]
coordinates {(-1,0,-4)} coordinate (c1);
\end{axis}
\draw[thick, -stealth] (c1) -- (c2);
\end{tikzpicture}
\end{document}

三个 plenes,两点之间有一个箭头

编辑:以下是 MWE 中上述代码的结构:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-6, xmax=6, ymin=-6, ymax=6, zmin=-6, zmax=6,]
\coordinate (c2) at (1,3,1); %one coordinate
\end{axis}
\begin{axis}[xmin=-6, xmax=6, ymin=-6, ymax=6, zmin=-6, zmax=6,]
\coordinate (c1) at (-1,0,-4); %an other coordinate
\end{axis}
\draw[thick, -stealth] (c1) -- (c2); %connecting the two coordinates
\end{tikzpicture}
\end{document}

相关内容