我有這個 3D 圖:
我想繪製函數僅有的底部較暗的一半區域(靠近我們的部分)。
這是一個 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,
]
\addplot3[
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}
我嘗試使用y domain = 0:x
,但這甚至無法編譯(需要很長時間,然後就崩潰了)。有什麼建議麼?
答案1
像這樣的東西嗎? (請注意,如果您想要一個非常舊的版本而不是\pgfplotsset{compat=1.16}
這個版本,則必須稍微修改,即\clip
需要在座標前面加上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)});
\addplot3[
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}