I'm trying to plot some data into a histogram using pyplot.hist as such:
hst = pp.figure()
pp.hist(spkSum)
hst.show()
spkSum contains the following data:[1, 1, 9, 9, 20, 20, 33, 33, 50, 50]
Ideally, I should have a vertical histogram whose bars sit neatly on the x-axis, reaching up to their respective values on the y-axis. Instead, I have this:
How can I fix this figure?
The axes aren't switched. You gave hist
a list of numbers, five distinct numbers repeated twice, and it computed a histogram appropriately. Maybe you're looking for a bar plot?
import matplotlib.pyplot as pp
spkSum = [1, 1, 9, 9, 20, 20, 33, 33, 50, 50]
pp.bar(range(len(spkSum)), spkSum)
gives
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