Filling In Region of 3D Plot












2















I am trying to fill in the area under this 3D graph, using the idea from this post. Here is a MWE for the function I want to plot under:



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}


Here is the result:



enter image description here



Now, here is the MWE with the code that should shade in the sides:



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}


And this is the result:



enter image description here



Can anyone make any suggestions as to what is going on? It seems when I add multiple functions to the same plot via addplot3, everything gets messed up.



Sorry if this seems like a "just fix this for me," but I have no idea what I'm doing wrong.



EDIT



I now see that for some reason, when adding the new plots to shade in the side, the domain was changed from (0,2) to (-4,4), so setting the domain as you add the plots helps:



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}


And here is the result:



enter image description here



My question now is, why is the original function shifted up?



ANOTHER EDIT



I have figured out a way to get what I want (not including the excellent answers below), but I still have some more concerns. Here is a MWE with a good result:



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}


Which give this result:



enter image description here



Now, the issue is the %shader=interp, line. When I uncomment this out, this happens:



enter image description here



So does this command force the graph to shift upwards for some reason? Why does this happen?










share|improve this question

























  • I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

    – Aiden Kenny
    18 hours ago
















2















I am trying to fill in the area under this 3D graph, using the idea from this post. Here is a MWE for the function I want to plot under:



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}


Here is the result:



enter image description here



Now, here is the MWE with the code that should shade in the sides:



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}


And this is the result:



enter image description here



Can anyone make any suggestions as to what is going on? It seems when I add multiple functions to the same plot via addplot3, everything gets messed up.



Sorry if this seems like a "just fix this for me," but I have no idea what I'm doing wrong.



EDIT



I now see that for some reason, when adding the new plots to shade in the side, the domain was changed from (0,2) to (-4,4), so setting the domain as you add the plots helps:



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}


And here is the result:



enter image description here



My question now is, why is the original function shifted up?



ANOTHER EDIT



I have figured out a way to get what I want (not including the excellent answers below), but I still have some more concerns. Here is a MWE with a good result:



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}


Which give this result:



enter image description here



Now, the issue is the %shader=interp, line. When I uncomment this out, this happens:



enter image description here



So does this command force the graph to shift upwards for some reason? Why does this happen?










share|improve this question

























  • I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

    – Aiden Kenny
    18 hours ago














2












2








2








I am trying to fill in the area under this 3D graph, using the idea from this post. Here is a MWE for the function I want to plot under:



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}


Here is the result:



enter image description here



Now, here is the MWE with the code that should shade in the sides:



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}


And this is the result:



enter image description here



Can anyone make any suggestions as to what is going on? It seems when I add multiple functions to the same plot via addplot3, everything gets messed up.



Sorry if this seems like a "just fix this for me," but I have no idea what I'm doing wrong.



EDIT



I now see that for some reason, when adding the new plots to shade in the side, the domain was changed from (0,2) to (-4,4), so setting the domain as you add the plots helps:



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}


And here is the result:



enter image description here



My question now is, why is the original function shifted up?



ANOTHER EDIT



I have figured out a way to get what I want (not including the excellent answers below), but I still have some more concerns. Here is a MWE with a good result:



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}


Which give this result:



enter image description here



Now, the issue is the %shader=interp, line. When I uncomment this out, this happens:



enter image description here



So does this command force the graph to shift upwards for some reason? Why does this happen?










share|improve this question
















I am trying to fill in the area under this 3D graph, using the idea from this post. Here is a MWE for the function I want to plot under:



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}


Here is the result:



enter image description here



Now, here is the MWE with the code that should shade in the sides:



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}


And this is the result:



enter image description here



Can anyone make any suggestions as to what is going on? It seems when I add multiple functions to the same plot via addplot3, everything gets messed up.



Sorry if this seems like a "just fix this for me," but I have no idea what I'm doing wrong.



EDIT



I now see that for some reason, when adding the new plots to shade in the side, the domain was changed from (0,2) to (-4,4), so setting the domain as you add the plots helps:



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}


And here is the result:



enter image description here



My question now is, why is the original function shifted up?



ANOTHER EDIT



I have figured out a way to get what I want (not including the excellent answers below), but I still have some more concerns. Here is a MWE with a good result:



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}


Which give this result:



enter image description here



Now, the issue is the %shader=interp, line. When I uncomment this out, this happens:



enter image description here



So does this command force the graph to shift upwards for some reason? Why does this happen?







tikz-pgf pgfplots 3d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 17 hours ago









Raaja

4,13121038




4,13121038










asked 18 hours ago









Aiden KennyAiden Kenny

3777




3777













  • I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

    – Aiden Kenny
    18 hours ago



















  • I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

    – Aiden Kenny
    18 hours ago

















I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

– Aiden Kenny
18 hours ago





I cannot find a picture of exactly what I need, but I just added another picture which is a closer resemblance to what I need. Pretty much I want to fill in the sides of the graph with the same color as the function.

– Aiden Kenny
18 hours ago










1 Answer
1






active

oldest

votes


















5














Something like this?



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}


enter image description here



Or, if you do the fills with



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;


you get



enter image description here



Notice that I added pgfplotsset{compat=1.16}. If you do not want that, you need to prepend the coordinates with 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;





share|improve this answer


























  • Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

    – Aiden Kenny
    18 hours ago











  • @AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

    – marmot
    17 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475636%2ffilling-in-region-of-3d-plot%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Something like this?



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}


enter image description here



Or, if you do the fills with



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;


you get



enter image description here



Notice that I added pgfplotsset{compat=1.16}. If you do not want that, you need to prepend the coordinates with 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;





share|improve this answer


























  • Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

    – Aiden Kenny
    18 hours ago











  • @AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

    – marmot
    17 hours ago
















5














Something like this?



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}


enter image description here



Or, if you do the fills with



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;


you get



enter image description here



Notice that I added pgfplotsset{compat=1.16}. If you do not want that, you need to prepend the coordinates with 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;





share|improve this answer


























  • Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

    – Aiden Kenny
    18 hours ago











  • @AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

    – marmot
    17 hours ago














5












5








5







Something like this?



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}


enter image description here



Or, if you do the fills with



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;


you get



enter image description here



Notice that I added pgfplotsset{compat=1.16}. If you do not want that, you need to prepend the coordinates with 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;





share|improve this answer















Something like this?



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}


enter image description here



Or, if you do the fills with



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;


you get



enter image description here



Notice that I added pgfplotsset{compat=1.16}. If you do not want that, you need to prepend the coordinates with 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;






share|improve this answer














share|improve this answer



share|improve this answer








edited 17 hours ago

























answered 18 hours ago









marmotmarmot

102k4119228




102k4119228













  • Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

    – Aiden Kenny
    18 hours ago











  • @AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

    – marmot
    17 hours ago



















  • Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

    – Aiden Kenny
    18 hours ago











  • @AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

    – marmot
    17 hours ago

















Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

– Aiden Kenny
18 hours ago





Exactly! I would like the sides to be the same color, but that can obviously be changed very easily.

– Aiden Kenny
18 hours ago













@AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

– marmot
17 hours ago





@AidenKenny Yes, that's simple, I added something. (In principle one could do it then in one stretch but that does not make the code substantially simpler).

– marmot
17 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475636%2ffilling-in-region-of-3d-plot%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to label and detect the document text images

Vallis Paradisi

Tabula Rosettana