简体   繁体   English

为什么轴打开了我的pyplot直方图?

[英]Why are the axes switched on my pyplot histogram?

I'm trying to plot some data into a histogram using pyplot.hist as such: 我正在尝试使用pyplot.hist将一些数据绘制成直方图:

hst = pp.figure()
pp.hist(spkSum)
hst.show()

spkSum contains the following data: [1, 1, 9, 9, 20, 20, 33, 33, 50, 50] spkSum包含以下数据: [1, 1, 9, 9, 20, 20, 33, 33, 50, 50] 1,1,9,9,20,20,33,33,50,50 [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. 理想情况下,我应该有一个垂直直方图,其条形图整齐地位于x轴上,在y轴上达到它们各自的值。 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. 你给了hist号码列表,重复两次五个不同的号码,并适当地计算出的直方图。 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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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