matplotlib/Python中条形图的单独标记条形 [英] Individually labeled bars for bar graphs in matplotlib / Python

查看:179
本文介绍了matplotlib/Python中条形图的单独标记条形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python中创建字母频率的条形图.我认为实现此目标的最佳方法是matplotlib,但是我无法解密文档.是否可以在matplotlib.pyplot.hist图的条上用每条字母代替数字轴标记一个字母?我认为一定是,但是我以前没有使用过matplotlib.

I am trying to create bar graphs of letter frequency in Python. I thought the best way to accomplish this would be matplotlib, but I have been unable to decipher the documentation. Is it possible to label the bars of a matplotlib.pyplot.hist plot with one letter per bar, instead of a numerical axis? I think it must be, but I have not used matplotlib before.

这是我想要的图形,显示为文本:

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.

使用答案和图片进行编辑(可以使用hist进行类似操作):

EDIT with answer and picture (can be done similarly with 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()


(来源: stevetjoa.com )


(source: stevetjoa.com)

这篇关于matplotlib/Python中条形图的单独标记条形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆