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!

3
  • Then it is not a histogram, but a plot. Commented Sep 28, 2017 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. Commented Sep 28, 2017 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. Commented Sep 28, 2017 at 15:39

1 Answer 1

-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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.