Does anyone know how to draw the Cumulative distribution function of Poisson Distribution (explained here) in tikzpicture environment? I tried with cumulative sums... without success. Many thanks!
Asked
Active
Viewed 302 times
1
-
One way is to get data from the table and then plot. – nidhin Oct 10 '19 at 13:18
-
See https://tex.stackexchange.com/q/60950. – Oct 10 '19 at 14:32
1 Answers
1
You can plot right-continuous function like the CDF of a Poisson distribution by using pfgplots with jump mark left, mark=*, e.g.

As minimal example:
\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}
Where the data is computed by python .\poisson_distribution.py given as
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])
Hajo
- 21