如何同时高亮显示多条曲线下的多个相交区域?

如何同时高亮显示多条曲线下的多个相交区域?

这是我的代码,如您所见,存在一个明显的缺陷,蓝色区域弹出并覆盖了其他区域。

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{tikzpicture}
    \begin{axis}[domain=2:8, samples=500, width=20cm]
        \addplot [no marks, fill=red, opacity=.2, draw=none, stack plots=y] {min(gauss(4,.5),gauss(6,.5)) } \closedcycle;
        \addplot [no marks, fill=blue, opacity=.2, draw=none, stack plots=y] {min(gauss(4,.5),gauss(4.5,.5)) } \closedcycle;
        \addplot [solid] {gauss(4,.5)} node[above, pos=.25, rotate=75] {};
        \addplot [solid] {gauss(4.5,.5)};
        \addplot [solid] {gauss(6,.5)};
    \end{axis}
\end{tikzpicture}

以下是当前结果的(剪辑的)屏幕截图:

显示当前结果的屏幕截图

答案1

这里是(带有一些评论)...

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{patterns}   % <-- needed to use `pattern's as you guess
    \pgfplotsset{
        compat=1.12,    % <-- to use Lua when using LuaLaTeX (which is faster)
    }
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        domain=2:8,
        samples=101,            % <-- reduced value to compile faster
%        width=20cm,            % <-- commented to see the lines better
        smooth,
    ]
        \addplot [
            no marks,
            fill=red,
            opacity=.2,
            draw=none,
%            stack plots=y,     % <-- that were causing the mess
        ] {min(gauss(4,.5),gauss(6,.5))}
            \closedcycle
        ;
        \addplot [
            no marks,
            % use `pattern' instead of `fill'
%            fill=blue,
            pattern=north west lines,
            opacity=.2,
            draw=none,
%            stack plots=y,
        ] {min(gauss(4,.5),gauss(4.5,.5))}
            \closedcycle
        ;
        \addplot [solid] {gauss(4,.5)}
            node [above, pos=.25, rotate=75] {};    % <-- what is is good for?
        \addplot [solid] {gauss(4.5,.5)};
        \addplot [solid] {gauss(6,.5)};
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容