Say I have an array of bin edges, and an array of bin values. (basically the output of plt.hist). For instance:
bins = np.array([1, 2, 3, 4, 5])
vals = np.array([2, 5, 5, 2])
How do I plot this as a histogram?
Edit: for clarity, I mean vals to be the "height" of each bin, where len(vals) + 1 = len(bins)
If you are using python 3.5 you can use pyplot fill_between function for such. You can use following code:
import numpy as np
import matplotlib.pyplot as plt
bins = np.array([1, 2, 3, 4, 5])
vals = np.array([2, 5, 5, 2])
plt.fill_between(bins,np.concatenate(([0],vals)), step="pre")
plt.show()
This will generate below graph:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With