Search code examples
pythoncdf

SciPy Cumulative Distribution Function Plotting


I am having troubles plotting a Cumulative Distribution Function.

So far I Have found this:

scipy.stats.beta.cdf(0.2,6,7)

But that only gives me a point.

This will be what I use to plot:

pylab.plot()
pylab.show()

What I want it to look like is this: File:Binomial distribution cdf.svg

with p = .2 and the bounds stopping once y = 1 or close to 1.


Solution

  • The first argument to cdf can be an array of values, rather than a single value. It will then return an array of values.

    import scipy.stats as stats
    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(0,20,100)
    cdf = stats.binom.cdf
    plt.plot(x,cdf(x, 50, 0.2))
    plt.show()
    

    enter image description here