首先,您可以像这样实现 CDF:
from bisect import bisect_left
class discrete_cdf:
def __init__(self, data):
self._data = data # must be sorted
self._data_len = float(len(data))
def __call__(self, point):
return (len(self._data[:bisect_left(self._data, point)]) /
self._data_len)
Run Code Online (Sandbox Code Playgroud)
使用上面的类,你可以像这样绘制它:
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)
Run Code Online (Sandbox Code Playgroud)
编辑: Anarange
在那里没有意义,对于 x 和 x+1 之间的所有点,cdf 将始终相同。