1

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!

Bernard
  • 271,350

1 Answers1

1

You can plot right-continuous function like the CDF of a Poisson distribution by using pfgplots with jump mark left, mark=*, e.g. enter image description here

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