我做了以下简单的 MWE 来解释约束函数:
\begin{tikzpicture}[scale=1]
\begin{axis}[xlabel=$x$, ylabel=$y$, zlabel={$z$}]
\addplot3 [surf, samples=20, domain=-4:4 ,color=gray!20,z buffer=auto] {4-x^2-y^2};
\addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({t},{2},{-t^2});
\addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({t},{-2},{-t^2});
\addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({2},{t},{-t^2});
\addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({-2},{t},{-t^2});
\end{axis}
\end{tikzpicture}
我的问题是:我们能否改变表面上矩形外区域的透明度,使其稍微淡化,以便我们可以通过集中矩形区域来解释约束函数?我不想删除整个形状。谢谢。
答案1
答案是肯定的。如果你将样本从 20 增加到 21,这很简单。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[xlabel=$x$, ylabel=$y$, zlabel={$z$}]
\addplot3 [surf, samples=21, domain=-4:4 ,color=gray!20,z
buffer=auto,opacity=0.3] {4-x^2-y^2};
\addplot3 [surf, samples=20, domain=-2:2 ,color=gray!20,z buffer=auto,
samples=11,samples y=11] {4-x^2-y^2};
% \addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({t},{2},{-t^2});
% \addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({t},{-2},{-t^2});
% \addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({2},{t},{-t^2});
% \addplot3 [variable=t,domain=-2:2,black, very thick, samples y=0, smooth] ({-2},{t},{-t^2});
\end{axis}
\end{tikzpicture}
\end{document}