# Plotting Normal distribution in pgfplots

I'm trying to reproduce the following diagram in TikZ and pgfplots.

My MWE with regenerated graph is below:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}
\begin{axis}[
no markers,
domain=0:6,
samples=100,
axis lines*=left,
xlabel=$x$,
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=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major
]

\draw [yshift=1.4cm, latex-latex](axis cs:2, 0) -- node [fill=white] {$0.683$} (axis cs:4, 0);
\draw [yshift=0.3cm, latex-latex](axis cs:1, 0) -- node [fill=white] {$0.954$} (axis cs:5, 0);

\end{axis}

\node[below] at (1, 0)  {$\mu - 2\sigma$};
\node[below] at (2, 0)  {$\mu - \sigma$};
\node[below] at (3, 0)  {$\mu$};

\end{tikzpicture}

\end{document}


Issues

1. Nodes are not properly placed.
2. How to remove y-axis?
3. How to draw vertical dotted line?

Any help will be highly appreciated. Thanks

-
– Jake Feb 26 at 16:20
You are better off using the tick options instead of adding the nodes manually. But if you want to add nodes manually, do it inside the axis environment and use the axis cs: coordinate system (as you did for the horizontal lines). – Qrrbrbirlbel Feb 26 at 16:20
Thanks @Qrrbrbirlbel for your helpful comment. You comment helped me to resolve one issue. Any idea about other two issues. – MYaseen208 Feb 26 at 16:25

1. As Qrrbrbirlbel said, move the nodes into the axis environment and use (axis cs:...). Alternatively, you could move the nodes into the axis environment and set disabledatascaling in the axis options. That way, you can keep your coordinates (this won't work if you have very large values in your plot, though).
2. Use hide y axis to hide the y axis
3. For the lines, I would redefine the gauss function to take a third parameter (the x value). Then you can use \pgfmathsetmacro to calculate the value of the distribution at the required x coordinate, and use that to draw the lines:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{tikzpicture}
\begin{axis}[
no markers,
domain=0:6,
samples=100,
ymin=0,
axis lines*=left,
xlabel=$x$,
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=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major,
hide y axis
]

\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};

\pgfmathsetmacro\valueA{gauss(1,3,1)}
\pgfmathsetmacro\valueB{gauss(2,3,1)}
\draw [gray] (axis cs:1,0) -- (axis cs:1,\valueA)
(axis cs:5,0) -- (axis cs:5,\valueA);
\draw [gray] (axis cs:2,0) -- (axis cs:2,\valueB)
(axis cs:4,0) -- (axis cs:4,\valueB);
\draw [yshift=1.4cm, latex-latex](axis cs:2, 0) -- node [fill=white] {$0.683$} (axis cs:4, 0);
\draw [yshift=0.3cm, latex-latex](axis cs:1, 0) -- node [fill=white] {$0.954$} (axis cs:5, 0);

\node[below] at (axis cs:1, 0)  {$\mu - 2\sigma$};
\node[below] at (axis cs:2, 0)  {$\mu - \sigma$};
\node[below] at (axis cs:3, 0)  {$\mu$};
\end{axis}

\end{tikzpicture}

\end{document}

-
 Thanks @jake. You are simply savoir for me always!!! – MYaseen208 Feb 26 at 16:41