2017-04-24 4 views
0

私はこのコードのどこかにバグがありますが、見つからないようです。最初の列にパーセンテージが表示されていません。迅速な修正が必要です!最初の列にパーセントが表示されない

import pandas as pd 
import matplotlib.pyplot as plt 

s = pd.Series(
    [8, 24, 21, 23, 24], 
    index = ["Your Plan", "Benchmark", "Region", "Industry", "Size"] 
) 

#Set descriptions: 
plt.title("INSERT TITLE HERE, PLEASE") 
plt.ylabel('Percentage of EEs Waiving') 

#Set tick colors: 
ax = plt.gca() 
ax.tick_params(axis='x', colors='black') 
ax.tick_params(axis='y', colors='black') 

#Plot the data: 
my_colors = ['#ffc000','#305496', '#8ea9db', '#b4c6e7', '#D9E1F2'] #red, green, blue, black, etc. 

s.plot(
    kind="bar", 
    color=my_colors, 
) 

# Rotate the desired axis (or undo the rotation) 
ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=0) 

# Set the Y Axis Limits 
ax.set_ylim([0,100]) 

#Adds data labels to top of bars 
for p in ax.patches[1:]: 
    h = p.get_height() 
    x = p.get_x()+p.get_width()/2. 
    if h != 0: 
     ax.annotate("%g" % p.get_height()+'%', xy=(x,h), xytext=(0,8), rotation=0, 
        textcoords="offset points", ha="center", va="bottom") 

plt.show() 
plt.savefig("PlanOffered.png") 

また、「Your Plan」とベンチマーク列の間に行を追加して、偉大な列を区切ることもできます。多くの人に感謝!

答えて

0

0thの代わりに1st要素で始まるループ内。

for p in ax.patches: 

に変更し、0th値の%ラベルを表示します。

  • line.linestyle='dashed'
  • すなわち、 docsのプロパティを参照してくださいあなたは x=0.5ラインの更なるスタイリングのために

    line = plt.axvline(x=0.5) 
    

    axvlineをプロットすることができ0th1stバーの間に垂直線を追加するには

  • line.color = 'black'
+0

恐ろしい!ありがとうございました。私たちは、ラインを黒く、色あせて(部分的に透明)、ダッシュラインの形にすることができたらどうしますか? –

関連する問題