在水平条形图的末尾添加值 [英] Adding values at the end of horizontal bar plots

查看:92
本文介绍了在水平条形图的末尾添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在水平条形图的末尾注释值:

I'm trying to annotate values at the end of my horizontal bar plot given by:

UK.groupby(['College/University']).size().sort_values(ascending=True).plot(kind='barh',figsize=(8,8),title='UK Uni')

如果这有帮助: y=list(UK.groupby(['College/University']).size()) 退货 [2, 1, 5, 2, 6, 1, 13, 1, 4, 1, 1, 1, 11, 1, 1, 2, 12]

If this helps: y=list(UK.groupby(['College/University']).size()) returns [2, 1, 5, 2, 6, 1, 13, 1, 4, 1, 1, 1, 11, 1, 1, 2, 12]

有什么主意吗? :)

推荐答案

使用可以使用matplotlib的注释功能为此:

Use can use matplotlib's annotation functionality for that:

sizes = UK.groupby(['College/University']).size().sort_values(ascending=True)
sizes.plot(kind='barh',figsize=(8,8),title='UK Uni')

for y, x in enumerate(sizes['size']):
    plt.annotate(str(x), xy=(x, y), va='center')

这篇关于在水平条形图的末尾添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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