First, you can implement CDF as follows:
from bisect import bisect_left
class discrete_cdf:
def __init__(data):
self._data = data
self._data_len = float(len(data))
def __call__(point):
return (len(self._data[:bisect_left(self._data, point)]) /
self._data_len)
Using the class above, you can build it like this:
from scipy.stats import norm
import matplotlib.pyplot as plt
cdf = discrete_cdf(your_data)
xvalues = range(0, max(your_data))
yvalues = [cdf(point) for point in xvalues]
plt.plot(xvalues, yvalues)
Edit: arange there does not make sense, cdf will always be the same for all points between x and x + 1.
source
share