pgfplots:填充三维中两条曲线之间的区域

pgfplots:填充三维中两条曲线之间的区域

我正在尝试创建一个图形来帮助解释不同类型的线积分。这涉及三维曲线(粗线)、其所遵循的 xy 平面中的曲线(虚线)以及 xz 和 yz 平面中的投影。我希望填充粗黑曲线和虚线曲线之间的区域,但无论我尝试什么,我得到的要么是没有填充,要么是下图所示的填充。我试过填充包,但这似乎不适用于 3D 图。任何关于如何实现这一点的想法都将不胜感激。

这是 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}

产生结果

在此处输入图片描述

答案1

实际上fillbetween对我来说确实有效。你只需要将形状放在不同的图层上,以使它们可见且不会相互覆盖:

\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}

在此处输入图片描述

相关内容