0

Supposed I have the data set [1,1,1,2,2] and want the bins [1,2),[2,3) then I can use the follwoing code to generate a histogram:

import matplotlib.pyplot as plt
data = [1,1,1,2,2]
values = [1,2,3]
plt.hist(data,bins = values)
plt.show()

Is there any way that I can give the height of each bin instead of the data? In this case it'd be 3 and 2 respectively.

Thanks!

Micah Pearce
  • 1,805
  • 3
  • 28
  • 61
  • Then it is not a histogram, but a plot. – Willem Van Onsem Sep 28 '17 at 15:28
  • This is a very simplified example of a histogram, but it actually is a histogram. It is at the same time a plot. If I can figure out the histogram side of things, I can extrapolate this to a much more complex scenario. – Micah Pearce Sep 28 '17 at 15:39
  • The "height of the bin" is the output of a histogram. Why use it as input? Or in other words, if you know the "height of the bin" you already have the histogram, so calling histogram with this data makes no sense. Presumably, you want a simple bar plot. – ImportanceOfBeingErnest Sep 28 '17 at 15:39

1 Answers1

-1

Bruno gave a good answer here:

How does numpy.histogram() work?

tl;dr

import matplotlib.pyplot as plt
plt.hist([1, 2, 1], bins=[0, 1, 2, 3])
Micah Pearce
  • 1,805
  • 3
  • 28
  • 61