Python Pandas:固定宽度的直方图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17523545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas : histogram with fixed width
提问by MatthieuBizien
I have data which I want to do an histogram, but I want the histogram to start from a given value and the width of a bar to be fixed. For example, for the serie [1, 3, 5, 10, 12, 20, 21, 25], I want, instead of
我有我想做直方图的数据,但我希望直方图从给定的值开始,条形的宽度是固定的。例如,对于系列 [1, 3, 5, 10, 12, 20, 21, 25],我想要,而不是
>>> p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=3).figure
# | |
# | | |
# | | |
# 0 8.5 17
I want the bars to have a width of 10 :
我希望条形的宽度为 10 :
| |
| | |
| | |
0 10 20
How can I do that ?
我怎样才能做到这一点 ?
EDIT : I eventually get what I wanted
编辑:我最终得到了我想要的
采纳答案by tacaswell
I think
我认为
p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=[0, 10, 20, 30]).figure
will do what you want. Alternately you can do
会做你想做的。或者你可以做
p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=3, range=(0,30)).figure
See documentationfor hist
and the documentationfor np.histogram
.
I suspect you are also running into some issues because it is labeling the centerof the bins, not the edges.
我怀疑您也遇到了一些问题,因为它标记的是垃圾箱的中心,而不是边缘。