2

I want to plot the probability density function of a Poisson distribution in python created using scipy. If I want to plot the pdf of a beta distribution, I would do something like the following:

x = np.linspace(0, 1, 200)
alphas = 4
betas = 10
pdf = st.beta.pdf(x, alpha, beta)
plt.plot(x, pdf, label=r'$\alpha$ = {}, $\beta$ = {}'.format(alpha, beta))

I thought I could do the same with a Poisson distribution, but unfortunately, the object does not have the pdf method! why? how can I plot a Poisson pdf without writing the formula myself?

Shashin Bhayani
  • 1,551
  • 3
  • 16
  • 37
DarioB
  • 1,349
  • 2
  • 21
  • 44

1 Answers1

6

The poisson distribution is a discrete distribution and does not have a density function. It however has a mass function, which you can access using scipy.stats.poisson.pmf().

Dennis F
  • 145
  • 4
  • Correct, however, it does not behave as you would expect. If you use poisson.pmf in place of beta.pdf, the graph is wrong, and the values are all close to zero. How would I plot that? – DarioB Apr 12 '19 at 09:58
  • 1
    @DarioB: `poisson.pmf(np.arange(5), mu=1) ` returns `array([0.36787944, 0.36787944, 0.18393972, 0.06131324, 0.01532831])`, which agrees with the plot labeled λ = 1 on the [wikipedia page on the Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution). Be sure you only pass in integers as the first argument to the pmf function. – Warren Weckesser Apr 12 '19 at 10:26
  • Yes, the passed values needs to be integers, The function do not takes non discrete values. Thanks! – DarioB Apr 12 '19 at 11:18