简体   繁体   中英

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:

情节

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM