【发布时间】:2014-02-21 03:58:36
【问题描述】:
如果我有一个单词字典及其在字符串中出现的频率,例如:
{'hello': 3, 'how': 4, 'yes': 10, 'you': 11, 'days': 10, 'are': 20, 'ago': 11}
如何使用 matplotlib 制作条形图?我发现了一个以前的问题,它有一个看似不错的解决方案,但它对我不起作用 (python: plot a bar using matplotlib using a dictionary)
当我跑步时
plt.bar(range(len(d)), d.values(), align="center")
plt.xticks(range(len(d)), d.keys())
我得到了错误
TypeError: 'dict_keys' object does not support indexing
我真的不知道我在哪里索引我的字典。可能是因为在我得到代码的问题中,x 值也是数字?我不确定。
【问题讨论】:
标签: python dictionary matplotlib