Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the axes switched on my pyplot histogram?

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:

plot

How can I fix this figure?

like image 881
Louis Thibault Avatar asked Dec 27 '22 03:12

Louis Thibault


1 Answers

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

enter image description here

like image 198
DSM Avatar answered Dec 30 '22 02:12

DSM