Ich versuche, den Bereich unter diesem 3D-Diagramm auszufüllen, indem ich die Idee von verwendedieser Beitrag. Hier ist ein MWE für die Funktion, unter der ich plotten möchte:
\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}
Hier ist das Ergebnis:
Hier ist nun das MWE mit dem Code, dersollenSchatten an den Seiten:
\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}
Und das ist das Ergebnis:
Kann mir jemand einen Vorschlag machen, was hier los ist? Es scheint, dass \addplot3[]
alles durcheinander gerät, wenn ich über mehrere Funktionen zum selben Plot hinzufüge.
Entschuldigen Sie, wenn das wie ein „Reparieren Sie das einfach für mich“-Gebraucht klingt, aber ich habe keine Ahnung, was ich falsch mache.
BEARBEITEN
Ich sehe jetzt, dass aus irgendeinem Grund beim Hinzufügen der neuen Diagramme zum Schattieren an der Seite die Domäne von (0,2) auf (-4,4) geändert wurde. Daher ist es hilfreich, die Domäne beim Hinzufügen der Diagramme festzulegen:
\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}
Und hier ist das Ergebnis:
Meine Frage ist nun, warum wird die ursprüngliche Funktion nach oben verschoben?
EINE WEITERE BEARBEITUNG
Ich habe einen Weg gefunden, das zu bekommen, was ich will (die hervorragenden Antworten unten ausgenommen), aber ich habe noch weitere Bedenken. Hier ist ein MWE mit einem guten Ergebnis:
\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}
Was zu diesem Ergebnis führt:
Das Problem ist nun die %shader=interp,
Zeile. Wenn ich diese auskommentiere, passiert Folgendes:
Erzwingt dieser Befehl aus irgendeinem Grund eine Verschiebung des Graphen nach oben? Warum geschieht dies?
Antwort1
Etwas wie das?
\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}
Oder, wenn Sie die Füllungen mit
\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;
du erhältst
Beachten Sie, dass ich hinzugefügt habe \pgfplotsset{compat=1.16}
. Wenn Sie das nicht möchten, müssen Sie den Koordinaten voranstellen: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;