Matplotlib: Histogram from a list of frequencies

落花浮王杯 提交于 2021-02-16 15:43:25

问题


I have a list x = [90, 100, 121, 123, 88]. These values in the list are frequencies of occurrence of an event in 5 different trials. I am looking to create a histogram from this list.

I simply tried:

plt.hist(x)
plt.show()

I get this:

I need something like this:

Note: Very New to Python. And still learning when and how to use Stackoverflow.


回答1:


Since the list x contains the frequencies then use a bar plot:

x = [90, 100, 121, 123, 88]

plt.bar(range(1,6), x)
plt.ylabel('frequency')
plt.show()



来源:https://stackoverflow.com/questions/52857413/matplotlib-histogram-from-a-list-of-frequencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!