物理数据的高斯分布

物理数据的高斯分布

我必须使用 pgfplots 对一些物理数据进行高斯分布。数据有 5 个,全部介于 21.00 和 22.00 之间,mu=21.52 e sigma=0.013。所以我想绘制高斯函数并标记与我的数据相对应(这是我能做的部分)我可以得到一些帮助吗?

\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}

答案1

您对绘制高斯函数的需求受到pgfplots软件包绘制能力的限制:-(。如果我正确解码了gauss函数中参数的含义,那么我将获得:

在此处输入图片描述

这些图像可以分为三段绘制。其中一段提到了以下能力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}

答案2

我不确定众多变化中的哪一个真正敲响了警钟。

\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}

演示

相关内容