Home Ask Login Register

Developers Planet

Your answer is one click away!

Anthony Lethuillier February 2016

Python histogram with pre-set size of bins

How would I go by if I wanted to plot a histogram when I already have the bins and their size ?

If I use :

plt.hist(x, bins)

it considers x as a list of results and not the already defined value of the corresponding bin.

Thanks

Answers


kazemakase February 2016

In that case you can simply create a bar chart with plt.bar:

plt.bar(bins[:, 0], x, bins[:, 1] - bins[:, 0])

I simply assumed bins is an array of shape (n, 2), where nis the number of bins. The first column is the lowest value covered by the bin and the second column is the upper value covered by the bin.

Post Status

Asked in February 2016
Viewed 3,662 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life