Matplotlib:频率列表中的直方图

时间:2018-10-17 14:32:46

标签: python list matplotlib histogram

我有一个列表x = [90,100,121,123,88]。列表中的这些值是5种不同试验中事件发生的频率。我正在寻找从此列表创建直方图。

我只是尝试过:

plt.hist(x)
plt.show()

我明白了: This is what I get but not what I am aiming to get

我需要这样的东西: Similar to what I need. Frequencies on the y axis. X-axis can simply be the indices

注意:Python的新手。而且仍在学习何时以及如何使用Stackoverflow。

1 个答案:

答案 0 :(得分:0)

由于列表x包含频率,因此请使用条形图:

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

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

enter image description here