【发布时间】:2017-09-04 16:00:06
【问题描述】:
在尝试使用 matplotlib 的 hist 函数绘制累积分布函数 (CDF) 时,最后一点回到零。我读了一些线程解释这是因为类似直方图的格式,但找不到适合我的情况的解决方案。
这是我的代码:
import matplotlib.pyplot as plt
x = [7.845419,7.593756,7.706831,7.256211,7.147965]
fig, ax=plt.subplots()
ax.hist(x, cumulative=True, normed=1, histtype='step', bins=100, label=('Label-1'), lw=2)
ax.grid(True)
ax.legend(loc='upper left')
plt.show()
生成以下图像
如您所见,阶跃函数在直方图的最后一个 bin 之后变为零,这是不希望的。如何更改我的代码以使 CDF 不会回到零?
谢谢
【问题讨论】:
-
嗨@ImportanceOfBeingErnest。感谢您的回答。我在问题中添加了完整的代码。
-
我明白了。我以minimal reproducible example 的形式编辑了问题,使问题变得清晰。 (而且我想请您下次提问时提供这种形式的问题,因为这样可以节省大家很多时间。)
-
查看 OP stackoverflow.com/q/10690094/3797285 给出的 hack
标签: python pandas matplotlib