Estoy tratando de completar el área debajo de este gráfico 3D, usando la idea deesta publicación. Aquí hay un MWE para la función que quiero trazar:
\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}
Aquí está el resultado:
Ahora, aquí está el MWE con el código quedeberíasombra en los lados:
\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}
Y este es el resultado:
¿Alguien puede hacer alguna sugerencia sobre lo que está pasando? Parece que cuando agrego varias funciones a la misma trama a través de \addplot3[]
, todo se estropea.
Lo siento si esto parece un "arréglalo por mí", pero no tengo idea de qué estoy haciendo mal.
EDITAR
Ahora veo que por alguna razón, al agregar los nuevos gráficos para sombrear en el costado, el dominio se cambió de (0,2) a (-4,4), por lo que configurar el dominio a medida que agrega los gráficos ayuda:
\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}
Y aqui esta el resultado:
Mi pregunta ahora es, ¿por qué se eleva la función original?
OTRA EDICIÓN
He descubierto una manera de conseguir lo que quiero (sin incluir las excelentes respuestas a continuación), pero todavía tengo algunas preocupaciones más. Aquí hay un MWE con un buen resultado:
\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}
Que dan este resultado:
Ahora, el problema es la %shader=interp,
línea. Cuando descomento esto, sucede esto:
Entonces, ¿este comando fuerza al gráfico a desplazarse hacia arriba por alguna razón? ¿Por qué pasó esto?
Respuesta1
¿Algo como esto?
\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}
O, si haces los rellenos con
\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;
usted obtiene
Note que agregué \pgfplotsset{compat=1.16}
. Si no desea eso, debe anteponer las coordenadas conaxis 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;