简体   繁体   English

蟒蛇; Matplotlib:将Bins的边界设置为整数值

[英]Python; Matplotlib: Set boundaries of Bins to integer values

I m drawing a histogram with matplot and I m wondering whether it is possible to set set boundaries of each bin to an integer value. 我正在用matplot绘制直方图,我想知道是否有可能将每个bin的设置边界设置为整数值。 Because if I interpret the Output values of my Plotting correctly it looks like that it is using floats. 因为如果我正确解释了“绘图”的“输出”值,就好像它正在使用浮点数。 Input: 输入:

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

Output for bins: 垃圾箱的输出:

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

Anyone has an idea? 有人有主意吗? And is it possible to set the boundaries manually? 是否可以手动设置边界?

Thx! 谢谢!

You can pass explicit bin edges to the plt.hist function. 您可以将明确的bin边缘传递给plt.hist函数。 For example, 例如,

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

In general, the number of bins will be equal to len(bins) - 1 . 通常,bin的数量将等于len(bins) - 1 In this example, bins will be equally spaced starting with the first bin from 0 to 50 and the last bin from 650 to 700. 在此示例中,从第一个容器从0到50,最后一个容器从650到700开始,容器将等距分布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM