有没有办法让这些轮廓线被前景的表面隐藏?

有没有办法让这些轮廓线被前景的表面隐藏?

有没有办法让这些轮廓线被前景中的表面隐藏?我只想看到背景中的轮廓线

在此处输入图片描述

\documentclass{standalone}

\usepackage{pgfplots}

\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[scale=1.8]
\begin{axis}[view={35}{40},
hide axis,
xlabel=$x$,ylabel=$y$,
mesh/interior colormap name=hot,
colormap/hot]
 \addplot3[domain=-2.5:2.5,surf,shader =faceted interp]
 {-exp(-0.5*x^2-0.5*y^2)};

\addplot3 [domain =-2.5:2.5, contour gnuplot = {number=2, labels={false},
  draw color = red}, samples = 21, ]
  {-exp(-0.5*x^2-0.5*y^2)};

 \end{axis}

 \end{tikzpicture} 

\end{document}

答案1

如果您不介意绘制两次表面并剪辑第二个图,您可以执行以下操作:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[scale=1.8,declare function={f(\x,\y)=-exp(-0.5*\x^2-0.5*\y^2);}]
\begin{axis}[view={35}{40},
hide axis,
xlabel=$x$,ylabel=$y$,
mesh/interior colormap name=hot,
colormap/hot]
 \addplot3[domain=-2.5:2.5,domain y=-2.5:2.5,surf,shader =faceted interp]
 {f(x,y)};

\addplot3 [domain =-2.5:2.5, contour gnuplot = {number=2, labels={false},
  draw color = red}, samples = 21]  {f(x,y)};
%\draw[blue,thick] 
\clip
plot[variable=\x,domain=-2.5:2.5] (\x,-2.5,{f(\x,-2.5)})  
-- plot[variable=\x,domain=-2.5:2.5] (2.5,\x,{f(2.5,\x)})   
to[out=-90,in=0] (0,0,{f(0,0)-0.1})
to[out=180,in=-90] (-2.5,-2.5,{f(-2.5,-2.5)});

\addplot3[domain=-2.5:2.5,domain y=-2.5:2.5,surf,shader =faceted interp]
 {f(x,y)};

\end{axis}

\end{tikzpicture} 

\end{document}

在此处输入图片描述

相关内容