Python;Matplotlib:将 Bins 的边界设置为整数值 [英] Python; Matplotlib: Set boundaries of Bins to integer values

查看:40
本文介绍了Python;Matplotlib:将 Bins 的边界设置为整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用matplot绘制直方图,我想知道是否有可能将每个bin的设置边界设置为整数值.因为如果我正确解释了绘图"的输出"值,就好像它正在使用浮点数.输入:

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. 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)

箱的输出:

[   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?

谢谢!

推荐答案

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

You can pass explicit bin edges to the plt.hist function. For example,

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

通常,bin的数量将等于 len(bins)-1 .在此示例中,bin 将等距间隔,从 0 到 50 的第一个 bin 和从 650 到 700 的最后一个 bin.

In general, the number of bins will be equal to 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.

这篇关于Python;Matplotlib:将 Bins 的边界设置为整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆