
如果不设置该
bins参数的自己,
plt.hist会为你选择(默认情况下,10)箱:
In [58]: n, bins, patches = plt.hist(X, normed=False, histtype='step', cumulative=True)In [59]: binsOut[59]: array([ 1.1 , 1.38, 1.66, 1.94, 2.22, 2.5 , 2.78, 3.06, 3.34, 3.62, 3.9 ])
返回值
bins显示matplotlib选择的垃圾箱的边缘。
听起来您想让X中的值充当bin边缘。使用
bins=sorted(X)+[np.inf]:
import numpy as npimport matplotlib.pyplot as pltX = [1.1, 3.1, 2.1, 3.9]bins = sorted(X) + [np.inf]n, bins, patches = plt.hist(X, normed=False, histtype='step', cumulative=True, bins=bins)plt.ylim([0, 5])plt.grid()plt.show()
产量
在
[np.inf]做出最终斌的右边缘延伸到无穷大。Matplotlib很聪明,不会尝试绘制非有限值,因此您所看到的只是最后一个bin的左边缘。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)