Matplotlib累积直方图-垂直线放置错误或误解?

Matplotlib累积直方图-垂直线放置错误或误解?,第1张

Matplotlib累积直方图-垂直线放置错误或误解?

如果不设置该

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的左边缘。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5617480.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存