gpt4 book ai didi

Python; Matplotlib : Set boundaries of Bins to integer values

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:20 25 4
gpt4 key购买 nike

我正在用 matplot 绘制直方图,我想知道是否可以将每个 bin 的边界设置为整数值。因为如果我正确解释绘图的输出值,它看起来就像使用 float 。输入:

plt.figure(figsize=(10,8))
(n, bins, patches) = plt.hist(counts.store_id.values, bins=10, rwidth=0.8)

垃圾箱的输出:

[   1.    66.2  131.4  196.6  261.8  327.   392.2  457.4  522.6  587.8 653. ]

有人有想法吗?是否可以手动设置边界?

谢谢!

最佳答案

您可以将显式 bin 边缘传递给 plt.hist 函数。例如,

bins = np.linspace(0, 700, 15)
plt.hist(counts.store_id.values, bins=bins)

一般来说,bin的数量将等于len(bins) - 1。在此示例中,各个 bin 的间距相等,第一个 bin 的编号为 0 到 50,最后一个 bin 的编号为 650 到 700。

关于Python; Matplotlib : Set boundaries of Bins to integer values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com