构造离散分布函数时如何去除垂直线?
import matplotlib.pyplot as plt
def plot_empirical_cdf(sample):
plt.hist(sample, histtype='step', cumulative=True, bins=len(sample))
plt.show()
sample = [123.0, 119.5, 120.5, 118.1, 117.5, 118.2, 124.5, 115.9, 121.0, 126.0, 121.3, 121.0, 118.2, 120.2, 124.3, 118.5, 117.2, 125.5, 115.0, 119.5, 126.0, 120.0, 126.5, 121.0, 125.0, 123.0, 122.7, 120.5, 122.5, 122.0, 122.5, 122.5, 122.5, 117.2, 123.0, 128.5, 120.5, 118.9, 116.2, 125.0, 125.1, 121.8, 122.0, 120.5, 123.0, 115.0, 120.5, 118.0, 125.0, 115.0, 117.0, 125.9, 122.0, 120.5, 121.1, 123.5, 120.7, 125.8, 120.5, 119.0, 120.5, 120.2, 123.0, 120.0, 117.2, 122.6, 120.2, 120.5, 123.0, 121.5, 120.0, 119.5, 115.0, 122.9, 123.3, 121.0, 122.5, 119.0, 124.0, 120.5, 121.9, 124.2, 121.5, 118.2, 122.2, 121.5, 120.0, 123.0, 119.5, 117.8, 119.2, 116.0, 123.0]
plot_empirical_cdf(sample)

任何建立在有限数量对象上的经验分布函数都将具有垂直步长。如果你真的需要 - 好吧,应用抗锯齿,但为什么呢?
顺便说一句,没有必要自己构建 CDF 函数,statsmodels.api 中的 distributions.ECDF(sample) 函数在这方面做得很好
但是如果你仍然需要一个平滑的函数,那么你可以这样做:
结果
我可以建议你这个解决方案:
得到这张照片: