如何将数据标签添加到seaborn countplot/factorplot [英] how to add data Labels to seaborn countplot / factorplot
本文介绍了如何将数据标签添加到seaborn countplot/factorplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用python3,seaborn countplot,我的问题:
I use python3, seaborn countplot, my question :
- 如何为每个条添加计数值?在顶部显示标签每个酒吧?
- 如何按降序排列这些条形?
我是这样写的:
fig = plt.figure(figsize=(10,6))
sns.countplot(data_new['district'],data=data_new)
plt.show()
非常感谢!
推荐答案
我使用了我生成的一个简单示例数据,但您可以将 df 名称和列名称替换为您的数据:
I used a simple example data I generated but you can replace the df name and column name to your data:
ax = sns.countplot(df["coltype"],
order = df["coltype"].value_counts().index)
for p, label in zip(ax.patches, df["coltype"].value_counts().index):
ax.annotate(label, (p.get_x()+0.375, p.get_height()+0.15))
这会产生:
您可能会稍微调整一下位置以使其看起来更好.
You will be likely to play around with the location a little bit to make it look nicer.
这篇关于如何将数据标签添加到seaborn countplot/factorplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文