2017-03-09 102 views
1

的条形码的情节剧:优化Matplotlib /大熊猫

df=pd.DataFrame([770,215,179,107,83,82,70,60,57,54,52],index = ['A','B','C','D','E','F','G','H','I','J','K']) 

ax = df.plot(kind='bar',stacked = False,alpha=0.75, rot=45,fontsize=20) 
ax.legend_.remove() 
for p in ax.patches: 
     ax.annotate(np.round(p.get_height(),decimals=0).astype(np.int64), (p.get_x()+p.get_width()/2., p.get_height()), ha='center', va='center', xytext=(2, 10), textcoords='offset points',fontsize=20) 
ax.patches[df.index.get_indexer(['B'])[0]].set_facecolor('r') 
ax.patches[df.index.get_indexer(['H'])[0]].set_facecolor('orange') 
plt.ylabel('y ',fontsize=25) 
plt.title('x',fontsize=30) 
plt.show() 
plt.save() 
plt.close() 

给下面的输出曲线: enter image description here

结果是完全正确的,但我不满意时单杆“A”在前面使所有其他酒吧如此微小和毫无意义。有没有什么办法来优化我的图表,'B' - 'K'看起来更大?我想到的想法是以y轴为0-300的方式拆分图形,但从300到800是300..800。或者任何其他建议,高度赞赏。谢谢。

回答

1

您可以使用对数y尺度提供ax.set_yscale('log')