spec / normal-dist-graph.texon commit [spec/methods] formatting fixes (41eacf2)
   1\pgfmathdeclarefunction{gauss}{2}{%
   2  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
   3}
   4
   5\pgfkeys{/pgf/decoration/.cd,
   6  distance/.initial=10pt
   7}
   8
   9\pgfdeclaredecoration{add dim}{final}{
  10  \state{final}{% 
  11    \pgfmathsetmacro{\dist}{5pt*\pgfkeysvalueof{/pgf/decoration/distance}/abs(\pgfkeysvalueof{/pgf/decoration/distance})}    
  12    \pgfpathmoveto{\pgfpoint{0pt}{0pt}}             
  13    \pgfpathlineto{\pgfpoint{0pt}{2*\dist}}   
  14    \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}} 
  15    \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{2*\dist}}     
  16    \pgfsetarrowsstart{latex}
  17    \pgfsetarrowsend{latex}
  18    \pgfpathmoveto{\pgfpoint{0pt}{\dist}}
  19    \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}} 
  20    \pgfusepath{stroke} 
  21    \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
  22    \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
  23}}
  24
  25\tikzset{dim/.style args={#1,#2}{decoration={add dim,distance=#2},
  26  decorate,
  27  postaction={decorate,decoration={text along path,
  28  raise=#2,
  29  text align={align=center},
  30  text={#1}}}}
  31}
  32
  33\begin{tikzpicture}
  34  \begin{axis}[every axis plot post/.style={
  35      mark=none,domain=-3:3,samples=50,smooth}, 
  36    axis x line=bottom, 
  37    axis y line=left,
  38    enlargelimits=upper,
  39    x=\textwidth/10,
  40    ytick={0.55},
  41    yticklabels={\(\frac{1}{\sigma \sqrt{2\pi}}\)}, 
  42    xtick={-2,-1,0,1,2},
  43    x tick label style = {font=\footnotesize},
  44    xticklabels={\((\mu-2\sigma)\), \((\mu-\sigma)\), \(\mu\), \((\mu+\sigma)\), \((\mu+2\sigma)\)},
  45    xlabel={\(x\)},
  46    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
  47    every axis y label/.style={at={(axis description cs:-0.02,0.2)}, anchor=south west, rotate=90},
  48    ylabel={\(\Pr(X=x)\)}]
  49    \addplot {gauss(0,0.75)};
  50    \fill[red!30] (-3,0)  -- plot[id=f3,domain=-3:3,samples=50] function {1/(0.75*sqrt(2*pi))*exp(-((x)^2)/(2*0.75^2))} -- (3,0) -- cycle;
  51    \fill[darkgray!30] (3,0)  -- plot[id=f3,domain=-3:3,samples=50] function {1/(0.75*sqrt(2*pi))*exp(-x*x*0.5/(0.75*0.75))} -- (3,0) -- cycle;
  52    \fill[lightgray!30] (-2,0)  -- plot[id=f3,domain=-2:2,samples=50] function {1/(0.75*sqrt(2*pi))*exp(-x*x*0.5/(0.75*0.75))} -- (2,0) -- cycle;
  53    \fill[white!30] (-1,0)  -- plot[id=f3,domain=-1:1,samples=50] function {1/(0.75*sqrt(2*pi))*exp(-x*x*0.5/(0.75*0.75))} -- (1,0) -- cycle;
  54    \begin{scope}[<->]
  55      \draw (-1,0.35) -- (1,0.35) node [midway, fill=white] {68.27\%};
  56      \draw (-2,0.25) -- (2,0.25) node [midway, fill=white] {95.35\%};
  57      \draw (-3,0.15) -- (3,0.15) node [midway, fill=white] {99.73\%};
  58    \end{scope}
  59    \begin{scope}[-, dashed, gray]
  60      \draw (-1,0) -- (-1, 0.35);
  61      \draw (1,0) -- (1, 0.35);
  62      \draw (-2,0) -- (-2, 0.25);
  63      \draw (2,0) -- (2, 0.25);
  64      \draw (-3,0) -- (-3, 0.15);
  65      \draw (3,0) -- (3, 0.15);
  66    \end{scope}
  67  \end{axis}
  68  \begin{axis}[every axis plot post/.append style={
  69      mark=none,domain=-3:3,samples=50,smooth}, 
  70    axis x line=bottom, 
  71    enlargelimits=upper,
  72    x=\textwidth/10,
  73    xtick={-2,-1,0,1,2},
  74    axis x line shift=30pt,
  75    hide y axis,
  76    x tick label style = {font=\footnotesize},
  77    xlabel={\(Z\)},
  78    every axis x label/.style={at={(axis description cs:1,-0.25)},anchor=south west}]
  79    \addplot {gauss(0,0.75)};
  80  \end{axis}
  81\end{tikzpicture}