4

I would like to "smooth" the area between the 2 gaussian curves obtained using this code : any suggestion would be appreciated. Thank you very much.

enter image description here

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\begin{document}


\begin{tikzpicture}[
  declare function={gauss(\x)=3*exp(-(\x/3)^2);},
  scale = 0.6,
  s/.style={shift=(0:9)}]
\fill [cyan!20]
          plot[domain= -4:4, samples=100] (\x, {gauss(\x)})
  {[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
       |- (-8,0)}
       -| cycle;

\filldraw[fill=pink!20, thick]
          plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
  {[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
       -- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})}
       -- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})
       -- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);     
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);   
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);   
\draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
\draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
\node[scale=0.65] at (0,1.5) {${1}$};
\node[scale=0.65] at (9,1.5) {${2}$};
% \draw[very thick] (0:8) -- ++ (up:.6);
%\draw[fill=gray!20] (0.85,-1.5) -- (0.85,0) -- (15.15,0) -- (15.15,-1.5) -- (0.85,-1.5);
\end{tikzpicture}

\end{document}
0

2 Answers 2

7

Why not just add the two bell curves together?

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\begin{document}


\begin{tikzpicture}[
  declare function={gauss(\x)=3*exp(-(\x/3)^2);},
  scale = 0.6,
  s/.style={shift=(0:9)}]
\fill [cyan!20]
          plot[domain= -4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9})
       |- (-4,0)
       -| cycle;

\filldraw[fill=pink!20, thick]
          plot[domain=-4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9)})
       -- plot[domain=13:-4, samples=100] (\x, {gauss(\x)+gauss(\x-9)+0.2})
       -- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);     
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);   
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);   
\draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
\draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
\node[scale=0.65] at (0,1.5) {${1}$};
\node[scale=0.65] at (9,1.5) {${2}$};
% \draw[very thick] (0:8) -- ++ (up:.6);
%\draw[fill=gray!20] (0.85,-1.5) -- (0.85,0) -- (15.15,0) -- (15.15,-1.5) -- (0.85,-1.5);
\end{tikzpicture}

\end{document}

demo

1
  • 1
    +1 This is a nice and simple solution.
    – dexteritas
    Commented Sep 18, 2023 at 15:24
4

Adaptations

  • added another plot in between, reusing the gauss function, and scaled and moved it
    plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
    
  • added some code comments
  • used rectange to draw blue rectangles at the bottom

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
    declare function={gauss(\x)=3*exp(-(\x/3)^2);},
    scale = 0.6,
    s/.style={shift=(0:9)}
]
    % double Gaussian
    \fill [cyan!20]
              plot[domain= -4:4, samples=100] (\x, {gauss(\x)})
           -- plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
      {[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
           |- (-8,0)}
           -| cycle;
    
    % top curve
    \filldraw[fill=pink!20, thick]
              plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
           -- plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
      {[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
           -- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})}
           -- plot[domain=4:-4, samples=100] (.125*\x+4.5, {3.59 - gauss(.15*\x)})
           -- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})
           -- cycle;
    
    % bottom rectangle background
    \path[fill=cyan!20] (-0.5,-2) rectangle (0.5,0);
    \path[fill=cyan!20] (8.5,-2) rectangle (9.5,0);
    
    % bottom
    \draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);     
    \draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);   
    \draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0); 
      
    % arrows
    \draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
    \draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
    
    % numbers
    \node[scale=0.65] at (0,1.5) {${1}$};
    \node[scale=0.65] at (9,1.5) {${2}$};
\end{tikzpicture}

\end{document}

Result

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .