2017-08-29 3 views
1

このトピックにいくつかの同様の投稿があります。しかし、彼らは私には役に立たなかった。barchartに値を表示

私は比較的新しいPythonと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から値を表示しようとしています。

答えて

3

パッチをループしてバーに注釈を付けます。

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 

出力:

enter image description here

+0

どうもありがとうございました。できます。 – dstrbd

関連する問題