0

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

MB-F
  • 22,770
  • 4
  • 61
  • 116
Anthony Lethuillier
  • 1,489
  • 4
  • 15
  • 33

1 Answers1

2

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.

Community
  • 1
  • 1
MB-F
  • 22,770
  • 4
  • 61
  • 116