Pandas : histogram with fixed width

matplotlib, pandas, python

Solution

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 documentation for `hist` and the documentation for `np.histogram`.

I suspect you are also running into some issues because it is labeling the center of the bins, not the edges.

Problem

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 ``` >>> 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 : ``` | | | | | | | | 0 10 20 ``` How can I do that ? EDIT : I eventually get what I wanted

Original source