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;

관련 정보