2

I have to make a gaussian distribution of some physics data using pgfplots. the data are 5, all between 21.00 and 22.00 with mu=21.52 e sigma=0.013. so i want to draw the function of the gaussian and have a mark corresponding to my data (this is the part i can do) may i have some help?

\begin{document}
\pgfmathdeclarefunction{gauss}{3}{
    \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
\begin{tikzpicture}
\begin{axis}[axis x line=bottom,axis y line=none,,xmin=21,xmax=22, title=Normal data distribution]
\addplot {gauss(x,21,1)};
\end{axis}
\end{tikzpicture}
cgnieder
  • 66,645
Daniel
  • 155

2 Answers2

2

your demand for drawing Gaussian function is at a limits of pgfplots package ability to drawing it :-(. if i correctly decode meaning of parameters in your gauss function, than i obtain:

enter image description here

this images can is draw in three segments. in one you cross mentioned ability of pgfplots:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%#3:  sigma
                                  %#2:  mu (expected value)
                                  %#1:  variable
    \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-(#1-#2)*(#1-#2)/(#3*#3)/2)}%
}%
\begin{tikzpicture}
\begin{axis}[axis x line=bottom, 
             axis y line=none,
             tick label style={font=\footnotesize},
             extra x ticks = {21.52},
             extra x tick labels = {$\mu$},
             title={Normal data distribution},
             mark=none, samples=30
             every axis plot post/.append style={very thick, color=red!50}
             ]
\addplot[domain=21:21.3]                {gauss(x,21.52,0.013)};
\addplot[samples=400, domain=21.3:21.7] {gauss(x,21.52,0.013)};
\addplot[domain=21.7:22]                {gauss(x,21.52,0.013)};
\end{axis}
\end{tikzpicture}
\end{document}
Zarko
  • 296,517
0

I'm not sure which of the many changes actually rang the bell.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%
    \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)*(#1-#2))/(2*#3*#3))}%
}%
\begin{tikzpicture}
\begin{axis}[axis x line=bottom, axis y line=none, title={Normal data distribution}]
\addplot[mark=none, domain=21:22] {gauss(x,21,1)};
\end{axis}
\end{tikzpicture}
\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120