【发布时间】:2016-03-10 18:14:30
【问题描述】:
如何正确地给 Pandas 条形图添加注释?
我正在关注Bar Chart Annotations with Pandas and MPL,但不知何故我无法将它变成我自己的代码——this is as far as I can go。怎么了?
我还发现了以下代码from here:
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
但我也不知道如何将它应用到我的代码中。请帮忙。
更新:
谢谢@CT Zhu 的回答。但是,在您的水平条中,您仍然将文本放在条的顶部,但我需要在它们内部或沿它们显示文本,就像我参考的文章中的这样,
他/她在哪里说,
“我非常喜欢水平条形图,因为我真的认为它们更容易阅读,但是,我知道很多人宁愿看到这个图表在常规条形图中实现。所以,这里是代码这样做;您会注意到为了创建注释而进行了一些更改"*
【问题讨论】:
标签: pandas matplotlib plot charts