假设我有一个类似下面的曲面图,我想修剪或裁剪红色曲线以外的区域(即红色曲线以外的区域不应显示任何颜色)。可以通过 来实现吗pgfplots
?提前致谢!
如果没有合理的方法来实现这一点,我会非常乐意找到一些解决方法......
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:1, colormap name=viridis, view={0}{90}]
\addplot3 [surf, shader=interp] {exp(-x^2-y^2)};
\addplot3 [smooth, thick, red] coordinates {(0,1,0) (0.75,0.75,0) (1,0,0)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:1, colormap name=viridis, view={0}{90}]
\clip (0,0) -- (0,1) -- plot[smooth] coordinates {(0,1,0) (0.75,0.75,0) (1,0,0)} -- cycle;
\addplot3 [surf, shader=interp] {exp(-x^2-y^2)};
\end{axis}
\end{tikzpicture}
\end{document}
- 或用红色曲线:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:1, colormap name=viridis, view={0}{90}]
\begin{scope}
\clip (0,0) -- (0,1) -- plot[smooth] coordinates {(0,1,0) (0.75,0.75,0) (1,0,0)} -- cycle;
\addplot3 [surf, shader=interp] {exp(-x^2-y^2)};
\end{scope}
\addplot3 [smooth, thick, red] coordinates {(0,1,0) (0.75,0.75,0) (1,0,0)};
\end{axis}
\end{tikzpicture}
\end{document}