# Restricting Domain of 3D Plot

I have this 3D plot:

I would like to plot the function only over the region over the darker half of the bottom (the part closer to us).

Here is a MWE:

\PassOptionsToPackage{usenames,dvipsnames,table,x11names}{xcolor}
\documentclass[a4paper, 12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,fillbetween}

\begin{document}

\begin{tikzpicture}

\begin{axis}[
zmax=15,
zmin=0,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(Tan), color=(Tan)},
xlabel = $s$,
ylabel = $h$,
zlabel = {$f(s,h)$},
ticks = none,
]

surf,
samples=30,
domain=0:1.5,
%y domain = 0:x, %does not work
opacity=0.5,
]
{12*exp(-(4*x+3*y))};

%highlighting dark part of bottom
\filldraw[Tan, fill = Tan, opacity = 0, fill opacity = 0.5] (0,0,0) -- (1.5,1.5,0) -- (1.5,0,0) -- (0,0,0);

%line across bottom
\draw[RawSienna, thick, opacity = 0.75] (0,0,0) -- (1.5,1.5,0);

%line going across graph
\addplot3 [domain=0:1.5, RawSienna, thick, samples=30, samples y=0, opacity = 0.75] (x,x,{12*exp(-(7*x))});

\end{axis}
\end{tikzpicture}

\end{document}


I tried to use y domain = 0:x, but that does not even compile (it takes too long and then craps out). Any suggestions?

• Maybe add a link to the previous question. This is a follow-up, or not? – Dr. Manuel Kuehner Feb 26 '19 at 10:27
• Haha it actually is the same question I'm working on, but the nature of this TeX problem I'm having is different from the last. – Aiden Kenny Feb 26 '19 at 10:33

Something like this? (Note that if you want a very old version instead of \pgfplotsset{compat=1.16} this will have to be slightly modified, i.e. the coordinates in \clip need to be prepended with axis cs:, \clip plot[variable=\x,domain=0:1.5] (axis cs:\x,\x,{f(\x,\x)}) -- (axis cs:1.5,0,{f(1.5,1.5)}) -- (axis cs:0,0,{f(1.5,1.5)}) -- (axis cs:0,0,{f(0,0)});. )

\PassOptionsToPackage{usenames,dvipsnames,table,x11names}{xcolor}
\documentclass[a4paper, 12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{colormaps,fillbetween}

\begin{document}

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

\begin{axis}[
zmax=15,
zmin=0,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(Tan), color=(Tan)},
xlabel = $s$,
ylabel = $h$,
zlabel = {$f(s,h)$},
ticks = none,
]

\begin{scope}
\clip plot[variable=\x,domain=0:1.5] (\x,\x,{f(\x,\x)})
-- (1.5,0,{f(1.5,1.5)}) -- (0,0,{f(1.5,1.5)}) -- (0,0,{f(0,0)});
surf,
samples=30,
domain=0:1.5,
%y domain = 0:x, %does not work
opacity=0.5,
] {f(x,y)};
\end{scope}

%highlighting dark part of bottom
\filldraw[Tan, fill = Tan, opacity = 0, fill opacity = 0.5] (0,0,0) -- (1.5,1.5,0) -- (1.5,0,0) -- (0,0,0);

%line across bottom
\draw[RawSienna, thick, opacity = 0.75] (0,0,0) -- (1.5,1.5,0);

line going across graph
\addplot3 [domain=0:1.5, RawSienna, thick, samples=30, samples y=0, opacity = 0.75]
(x,x,{f(x,x)});

\end{axis}
\end{tikzpicture}

\end{document}


• +1: This will go in to by code bucket :) – Dr. Manuel Kuehner Feb 26 '19 at 15:59
• Yes, this is exactly what I had in mind! For what reason did you say the code will have to be modified in \pgfplotsset{compat=1.16}? Because it works fine for me! – Aiden Kenny Feb 26 '19 at 19:50
• @AidenKenny That's a typo. I wanted to write: "Note that if you want a very old version instead of \pgfplotsset{compat=1.16} this will have to be slightly modified.", the reason being that with very old versions you need to prepend the coordinates in \clip with axis cs:. – user121799 Feb 26 '19 at 19:56
• @AidenKenny Thanks for spotting this! It was indeed very misleading. – user121799 Feb 26 '19 at 20:16