我尝试将泊松分布绘制为离散图,但只发现如下连续图示例:
公式为:
&space;0“ 目标=”空白">&space;0" title="P{\lambda}(k) = \frac{\lambda^k}{k!}e^{-\lambda} \quad 其中 \quad k \in \mathbb{N}_0,\quad \lambda > 0" />
答案1
这是绘制离散泊松函数的方法。已添加ycomb
到链接中的示例,这使得情节变得离散而不连续。
\documentclass{standalone}
\usepackage{pgfplots, tikz}
\pgfmathdeclarefunction{poiss}{1}{%
\pgfmathparse{(#1^x)*exp(-#1)/(x!)}%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=center,
axis y line=center,
xtick={0,2,...,19},
ytick={0.1,0.2,...,0.4},
domain = 0:18,
samples = 19,
xlabel={$k$},
ylabel={$P[k]$},
xlabel style={right},
ylabel style={above left},
ymax=0.5,
xmax=20,
x post scale=1.4
]
\addplot+[ycomb,blue,thick] {poiss(1))};
\addlegendentry{$\lambda = 1$}
\addplot+[ycomb,red,thick] {poiss(5))};
\addlegendentry{$\lambda = 5$}
\addplot+[ycomb,brown,thick] {poiss(9))};
\addlegendentry{$\lambda = 9$};
\end{axis}
\end{tikzpicture}
\end{document}