3Dプロットの領域を塗りつぶす

3Dプロットの領域を塗りつぶす

私は、この3Dグラフの下の領域を、この郵便受けプロットしたい関数の MWE は次のとおりです。

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

\begin{document}

\begin{tikzpicture}
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\begin{axis}[
zmax=1.25,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(SteelBlue3), color=(SteelBlue3)},
xlabel = $x$,
ylabel = $y$,
zlabel = {$f(x,y)$},
]

\addplot3[
surf,
samples=30,
domain=0:2,
shader=interp,
opacity=0.5,
]
{exp(-(x^2+y^2))};

\end{axis}
\end{tikzpicture}

\end{document}

結果は次のとおりです。

ここに画像の説明を入力してください

さて、ここにMWEのコードがありますすべき側面に陰影をつける:

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

\begin{document}

\begin{tikzpicture}
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\begin{axis}[
zmax=1.25,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(SteelBlue3), color=(SteelBlue3)},
xlabel = $x$,
ylabel = $y$,
zlabel = {$f(x,y)$},
]

\begin{pgfonlayer}{pre main}
\addplot3[
surf,
samples=30,
domain=0:2,
shader=interp,
opacity=0.5,
]
{exp(-(x^2+y^2))};
\end{pgfonlayer}

\addplot3 [name path = xline, draw = none] (x,0,0);
 % x is the variable
 % second 0 is the y coordinate of the leftmost part of the graph
 % third 0 is height
\addplot3 [name path = yline, draw = none] (2,y,0);
 % y is the variable
 % first 2 is the x coordinate of the rightmost part of the graph
 % third 0 is height
\addplot3 [name path = xcurve, y domain = 0:0, draw = none] 
    (x, 0, {exp(-x^2)});
 % now instead of height being 0, it is height of function
\addplot3 [name path = ycurve, y domain = 0:0, draw = none]
  (2, x, {exp(-(x^2 + 4))});
 % same idea
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = xcurve and xline];
 % fills in x axis
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = yline and ycurve, reverse = true];

\end{axis}
\end{tikzpicture}

\end{document}

そして、これが結果です:

ここに画像の説明を入力してください

何が起こっているのか、誰か何か提案できますか? を介して同じプロットに複数の関数を追加すると\addplot3[]、すべてが台無しになるようです。

「とにかくこれを直してください」と言っているように思われたら申し訳ありませんが、何が間違っているのか全く分かりません。

編集

何らかの理由で、新しいプロットを追加して側面を陰影付けすると、ドメインが (0,2) から (-4,4) に変更されたことがわかりました。そのため、プロットを追加するときにドメインを設定すると役立ちます。

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

\begin{document}

\begin{tikzpicture}
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\begin{axis}[
zmax=1.25,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(SteelBlue3), color=(SteelBlue3)},
xlabel = $x$,
ylabel = $y$,
zlabel = {$f(x,y)$},
]

\begin{pgfonlayer}{pre main}
\addplot3[
surf,
samples=30,
domain=0:2,
shader=interp,
opacity=0.5,
]
{exp(-(x^2+y^2))};
\end{pgfonlayer}

\addplot3 [name path = xline, draw = none, domain=0:2] (x,0,0);
 % x is the variable
 % second 0 is the y coordinate of the leftmost part of the graph
 % third 0 is height
\addplot3 [name path = yline, draw = none, domain=0:2] (2,y,0);
 % y is the variable
 % first 2 is the x coordinate of the rightmost part of the graph
 % third 0 is height
\addplot3 [name path = xcurve, domain=0:2, y domain = 0:0, draw = none] 
    (x, 0, {exp(-x^2)});
 % now instead of height being 0, it is height of function
\addplot3 [name path = ycurve, domain=0:2, y domain = 0:0, draw = none]
  (2, x, {exp(-(x^2 + 4))});
 % same idea
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = xcurve and xline];
 % fills in x axis
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = yline and ycurve, reverse = true];

\end{axis}
\end{tikzpicture}

\end{document}

そして結果は次のとおりです。

ここに画像の説明を入力してください

私の疑問は、なぜ元の関数が上方にシフトされているのかということです。

別の編集

私は、自分が望むものを得る方法を見つけました (以下の優れた回答は除きます) が、まだいくつか懸念事項があります。以下は、良い結果が得られた MWE です。

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

\begin{document}

\begin{tikzpicture}

\begin{axis}[
zmax=1.25,
zmin=0,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(SteelBlue3), color=(SteelBlue3)},
xlabel = $x$,
ylabel = $y$,
zlabel = {$f(x,y)$},
]

\addplot3[
surf,
samples=30,
domain=0:2,
%shader=interp,
opacity=0.5,
]
{exp(-(x^2+y^2))};

\addplot3 [name path = xline, draw = none, domain=0:2] (x,0,0);
 % x is the variable
 % second 0 is the y coordinate of the leftmost part of the graph
 % third 0 is height
\addplot3 [name path = yline, draw = none, domain=0:2] (2,y,0);
 % y is the variable
 % first 2 is the x coordinate of the rightmost part of the graph
 % third 0 is height
\addplot3 [name path = xcurve, domain=0:2, y domain = 0:0, draw = none] 
    (x, 0, {exp(-x^2)});
 % now instead of height being 0, it is height of function
\addplot3 [name path = ycurve, domain=0:2, y domain = 0:0, draw = none]
  (2, x, {exp(-(x^2 + 4))});
 % same idea
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = xcurve and xline];
 % fills in x axis
\addplot [color = SteelBlue3, opacity = 0.5, draw = none]
  fill between[of = yline and ycurve, reverse = true];

\end{axis}
\end{tikzpicture}

\end{document}

結果は次のようになります:

ここに画像の説明を入力してください

さて、問題は%shader=interp,行です。この行のコメントを外すと、次のようになります。

ここに画像の説明を入力してください

では、このコマンドは何らかの理由でグラフを強制的に上方にシフトさせるのでしょうか? なぜこのようなことが起こるのでしょうか?

答え1

このようなもの?

\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)=exp(-(\x*\x+\y*\y));}]
\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\begin{axis}[
zmax=1.25,
view = {45}{45},
grid=minor,
colormap={mycol}{color=(SteelBlue3), color=(SteelBlue3)},
xlabel = $x$,
ylabel = $y$,
zlabel = {$f(x,y)$},
]

\addplot3[
surf,
samples=30,
domain=0:2,
shader=interp,
opacity=0.5,
]
{f(x,y)};

\fill[blue] (0,0,-1) -- plot[variable=\x,domain=0:2] (\x,0,{f(\x,0)}) -- (2,0,-1) --
cycle;
\fill[blue!80] (2,0,-1) -- plot[variable=\y,domain=0:2] (2,\y,{f(2,\y)}) 
-- (2,2,-1) --cycle;

\end{axis}
\end{tikzpicture}

\end{document}

ここに画像の説明を入力してください

または、

\fill[SteelBlue3] (0,0,-1) -- plot[variable=\x,domain=0:2] (\x,0,{f(\x,0)}) -- (2,0,-1) --
cycle;
\fill[SteelBlue3] (2,0,-1) -- plot[variable=\y,domain=0:2] (2,\y,{f(2,\y)}) 
-- (2,2,-1) --cycle;

あなたは得る

ここに画像の説明を入力してください

を追加したことに注目してください\pgfplotsset{compat=1.16}。これを望まない場合は、座標の前にaxis cs:

\fill[SteelBlue3] (axis cs:0,0,-1) -- plot[variable=\x,domain=0:2] (axis cs:\x,0,{f(\x,0)}) -- (axis cs:2,0,-1) --
cycle;
\fill[SteelBlue3] (axis cs:2,0,-1) -- plot[variable=\y,domain=0:2] (axis cs:2,\y,{f(2,\y)}) 
-- (axis cs:2,2,-1) --cycle;

関連情報