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
In order to plot a histogram using pandas, chain the . hist() function to the dataframe. This will return the histogram for each numeric column in the pandas dataframe.
Pandas cut() function is used to separate the array elements into different bins . The cut function is mainly used to perform statistical analysis on scalar data.
To create a histogram the first step is to create bin of the ranges, then distribute the whole range of the values into a series of intervals, and count the values which fall into each of the intervals. Bins are clearly identified as consecutive, non-overlapping intervals of variables.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With