在条形图上显示值 [英] Displaying of values on barchart
本文介绍了在条形图上显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了几个与此主题类似的帖子.但是他们对我没有帮助.
I've found a couple of similar postings to this topic. But they wasn't helpful for me.
我是Python和Seaborn的新手.
I'm relatively new to Python and Seaborn.
这是我的代码:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
x_axis = ["A", "B","C","D","E","F"]
y_axis = [78.5, 79.6, 81.6, 75.4, 78.3, 79.6]
plt.ylabel('Accuracy')
plt.title('Accuracy of Classifier')
g=sns.barplot(x_axis, y_axis, color="red")
我只是想在每个小节的顶部显示y_axis的值.
I'm just trying to display the values from the y_axis on top of every bar.
推荐答案
浏览补丁并注释栏.
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
x_axis = ["A", "B","C","D","E","F"]
y_axis = [78.5, 79.6, 81.6, 75.4, 78.3, 79.6]
plt.ylabel('Accuracy')
plt.title('Accuracy of Classifier')
g=sns.barplot(x_axis, y_axis, color="red")
ax=g
#annotate axis = seaborn axis
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()),
ha='center', va='center', fontsize=11, color='gray', xytext=(0, 20),
textcoords='offset points')
_ = g.set_ylim(0,120) #To make space for the annotations
输出:
这篇关于在条形图上显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文