有人知道如何在 tikzpicture 环境中绘制泊松分布的累积分布函数(此处解释)吗?我尝试了累积和……但没有成功。非常感谢!
答案1
pfgplots
您可以使用绘制右连续函数,例如泊松分布的 CDF jump mark left, mark=*
,例如
作为最小的例子:
\documentclass{minimal}
\usepackage{tikz}% for programming graphics
\usepackage{pgfplots}% for scientific plots \begin{axis} etc
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.98\textwidth,
legend pos=north west,
grid=major,
]
\addplot[blue, ycomb, mark=*] table [x=k, y=pdf, col sep=comma]{poisson_distribution_data.csv};
\addplot[red, jump mark left, mark=*] table [x=k, y=cdf, col sep=comma]{poisson_distribution_data.csv};
\legend{
Poisson PDF with \(\lambda = 4\)\\
Poisson CDF \\
}
\end{axis}
\end{tikzpicture}
\end{document}
数据计算python .\poisson_distribution.py
如下
import numpy as np
import csv
lambda_0 = 4
with open('poisson_distribution_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["k", "pdf", "cdf", lambda_0])
s = 0
kmax = 12
for k in range(kmax):
pdf = np.exp(-lambda_0) * ((lambda_0 ** k) / np.math.factorial(k))
s += pdf
writer.writerow([k, pdf, s])