pythonplotscipyhistogramcdf

Binomial distribution CDF using scipy.stats.binom.cdf


I wrote below code to use binomial distribution CDF (by using scipy.stats.binom.cdf) to estimate the probability of having NO MORE THAN k heads out of 100 tosses, where k = 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100. and then I tried to plot it using hist().

import scipy
import matplotlib.pyplot as plt
def binomcdf():
    p = 0.5
    n = 100
    x = 0
    for a in range(10):
        print(scipy.stats.binom.cdf(x, n, p))
        x += 10

plt.hist(binomcdf())
plt.show()

but I don't know why my plot returns empty, and I receive below error, can anyone help please!

TypeError: 'NoneType' object is not iterable


Solution

  • I would save x and the corresponding cdf output for each associated x to a list, then return that list. Then use the data in the list to make plot.