![结合addplot3连接在两个不同轴上定义的两个点](https://linux22.com/image/473282/%E7%BB%93%E5%90%88addplot3%E8%BF%9E%E6%8E%A5%E5%9C%A8%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E8%BD%B4%E4%B8%8A%E5%AE%9A%E4%B9%89%E7%9A%84%E4%B8%A4%E4%B8%AA%E7%82%B9.png)
我想绘制类似以下代码的内容,其中我尝试连接在两个不同轴上定义的两个不同点。我用它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}
编辑:以下是 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}