简体   繁体   English

在matplotlib / Python中为条形图单独标记的条形图

[英]Individually labeled bars for bar graphs in matplotlib / Python

I am trying to create bar graphs of letter frequency in Python. 我试图在Python中创建字母频率的条形图。 I thought the best way to accomplish this would be matplotlib, but I have been unable to decipher the documentation. 我认为实现这一目标的最佳方法是matplotlib,但我无法破译文档。 Is it possible to label the bars of a matplotlib.pyplot.hist plot with one letter per bar, instead of a numerical axis? 是否可以标记matplotlib.pyplot.hist图的条形图,每个条形码只有一个字母,而不是数字轴? I think it must be, but I have not used matplotlib before. 我认为一定是,但我之前没有使用过matplotlib。

This is the sort of graph I'm after, rendered as text: 这是我之后的图形,呈现为文本:

|
|    *
|    *  *
| *  *  *
+----------
  A  B  C

Sure is! 当然是! You just need to reset the tick labels. 您只需重置刻度标签即可。

EDIT with answer and picture (can be done similarly with hist ): 用答案和图片编辑(可以用hist进行类似):

x = scipy.arange(4)
y = scipy.array([4,7,6,5])
f = pylab.figure()
ax = f.add_axes([0.1, 0.1, 0.8, 0.8])
ax.bar(x, y, align='center')
ax.set_xticks(x)
ax.set_xticklabels(['Aye', 'Bee', 'Cee', 'Dee'])
f.show()

替代文字
(source: stevetjoa.com ) (来源: stevetjoa.com

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

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