# pgfplots: Filling a region between two curves in 3D

I'm trying to create a figure to help explain different types of line integrals. This involves a curve in 3 dimensions (the thick line), the curve in the x-y plane that it follows (the dashed line), and the projections in the xz and yz planes. I would like to have the area between the thick black curve and the dashed curved filled, but whatever I try I get either no fill or the fill shown in the figure below. I've tried the fillbetween package, but that doesn't seem to work with 3D plots. Any thoughts on how to achieve this are gratefully appreciated.

Here's a MWE

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}[
declare function={mynorm(\m,\s) = 1/(2*\s*sqrt(pi))*exp(-    (x-\m)^2/(2*\s^2));}
]

\begin{axis}[
view={135}{45},
enlargelimits=false,
grid=major,
domain=0:16,
y domain=0:4,
samples=50,
xlabel=$x$,
ylabel=$y$,
]

\addplot3 [domain=0:4, samples=50, samples y=0, smooth, fill=gray!60] (x,0,{mynorm(1,0.5)}) \closedcycle;
\addplot3 [domain=0:16, samples=50, samples y=0, smooth, fill=gray!60] (0,x,{mynorm(1,0.5)}) \closedcycle;

\addplot3 [thick,domain=0:4, samples=50, samples y=0, smooth, fill=gray] (x,x^2,{mynorm(1.0,0.5)});
\addplot3 [domain=0:4, samples=50, samples y=0, smooth, dashed] (x,x^2,0);

\end{axis}

\end{tikzpicture}

\end{document}


which produces the result

• As nobody welcomed you when you asked your first question: Welcome to TeX.SX! – Jasper Habicht Feb 22 '18 at 22:15

Actually fillbetween does work for me. You only have to put the shapes on different layers in order to make them visible and not cover each other:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}[
declare function={mynorm(\m,\s) = 1/(2*\s*sqrt(pi))*exp(-    (x-\m)^2/(2*\s^2));}
]

\begin{axis}[
view={135}{45},
enlargelimits=false,
grid=major,
domain=0:16,
y domain=0:4,
samples=50,
xlabel=$x$,
ylabel=$y$,
]

\addplot3 [domain=0:4, samples=50, samples y=0, smooth, fill=gray!60, on layer=axis grid] (x,0,{mynorm(1,0.5)}) \closedcycle;
\addplot3 [domain=0:16, samples=50, samples y=0, smooth, fill=gray!60, on layer=axis grid] (0,x,{mynorm(1,0.5)}) \closedcycle;

\addplot3 [name path=A,thick,domain=0:4, samples=50, samples y=0, smooth] (x,x^2,{mynorm(1.0,0.5)});
\addplot3 [name path=B,domain=0:4, samples=50, samples y=0, smooth, dashed, on layer=axis foreground] (x,x^2,0);
\addplot3 [gray] fill between [of=A and B];
\end{axis}

\end{tikzpicture}

\end{document}


• Well, knock me down with a feather! I had tried multiple versions of that, but it never worked. I must have been missing something somewhere....Many thanks. – user3516417 Feb 22 '18 at 22:16
• It somehow has to do with the different layers. I had to try several times before it actually worked. I had to put the projections on the same layer as the grid, so now the ticks lie above the projections. – Jasper Habicht Feb 22 '18 at 22:20