I wants to make PDF diagram like that.

enter image description here

currently, i'm here. Can someone please help me out to complete the diagram further. Thanks in advance.

  no markers, domain=-5:5, samples=100,
  axis lines*=left, xlabel=$x$, ylabel=$y$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=5cm, width=12cm,
  xtick={-1,+1}, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = major
  \addplot [fill=black!20, draw=none, domain=-2.5:0] {gauss(+1,1)} \closedcycle ;
  \addplot [fill=black!20, draw=none, domain=0:+2.5] {gauss(-1,1)} \closedcycle ;
  \addplot [very thick,black!50!black] {gauss(-1,1)};
  \addplot [very thick,black!50!black] {gauss(+1,1)};
\draw (-.2,2.5) node[left] {$f_Y(u)$};
\draw (3,-.5) node[below] {$u$};
\draw[->] (0,0) -- (6.2,0) node[right] {};
\draw[->] (0,0) -- (0,5) node[above] {};
\draw [yshift=-0.6cm, latex-latex](axis cs:0,0) -- node [fill=white] {$1.96\sigma$} (axis cs:0,0);
  • 2
    It is hard to tell what differences are deliberate and which are accidental. It shouldn't be necessary to redraw the axes with arrows, but if you do, use (rel axis cs: ...). Aug 22, 2017 at 23:18

1 Answer 1


This might help towards your objective. I leave it to you to do the notation across the x-axis, since there is nothing to indicate the size of each interval.

The graph uses the fill between library from pgfplots to produce the filled areas. I defined some variables for the key parameters, which will make it easier for you to customize.

This is the result:

enter image description here

This is the code:






    \def\startx{-5}    % lower end of domain
    \def\endx{5}       % upper end of domain
    \def\camean{-1.0}  % mean of left side distribution
    \def\casigma{1.0}  % sigma for left side distribution
    \def\cbmean{1.0}   % mean for right side distribution
    \def\cbsigma{1.0}  % sigma for right side distribution
    \def\verticala{0.7} % x vale for first delimiter
    \def\verticalb{1.3} % x value for second delimited

    axis x line=middle,
    axis y line=middle,
    % Draw distributions
    \addplot [name path=a,thin, smooth] {gauss(\camean,\casigma)};
    \addplot [name path=b,thin, smooth] {gauss(\cbmean,\cbsigma)};%    
    % Draw vertical lines:
    \draw [gray, semithick] (\verticala,0) -- (\verticala,0.4);
    \draw [gray, semithick] (\verticalb,0) -- (\verticalb,0.4);
    % create path for x axis:
    \path[name path=axis] (axis cs:\startx,0) -- (axis cs:\endx,0);
    % generate fills:
    \addplot[darkgray]  fill between[of=a and axis,soft clip={domain=\verticala:\verticalb}]; % 
    \addplot[pattern=north east lines]  fill between[of=b and a,
    soft clip={(\verticala,0) rectangle (\verticalb,0.5)}
    % place the labels for each distribution
    \node (a) at (-1,0.45) {$p(y|1)$};
    \node (b) at (1,0.45) {$p(y|0)$};



You must log in to answer this question.

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