Setting the bin content of a histogram

Hi all,

I'm currently using the hist plot from matlibplot. Here I have the following
question: is there an easy way to set the bin content of a specified bin?
For example, I would like to call set_bin_content(bin_index=1, value=10000)
once instead of filling in 10000 times the same value.

Thank you very much.
Best regards

···

--
View this message in context: http://old.nabble.com/Setting-the-bin-content-of-a-histogram-tp33412466p33412466.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi,

I'm currently using the hist plot from matlibplot. Here I have the following
question: is there an easy way to set the bin content of a specified bin?
For example, I would like to call set_bin_content(bin_index=1, value=10000)
once instead of filling in 10000 times the same value.

You can do this by separating the histogram calculation from the plotting.

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

# generate data here; for example
data = np.random.randn(500)

myHist, myBinEdges = np.histogram(data)

# edit myHist to your heart's delight

wid = myBinEdges[1:] - myBinEdges[:-1]
plt.bar(myBinEdges[:-1], myHist, width=wid)
plt.show()

-Jeff

Hi Jeff,

thank you for your answer. It was very helpful to me.

Have a nice weekend!
-Jan

···

--
View this message in context: http://old.nabble.com/Setting-the-bin-content-of-a-histogram-tp33412466p33428602.html
Sent from the matplotlib - users mailing list archive at Nabble.com.