Matplotlib / Pandas中条形图的优化

时间:2017-03-09 14:18:06

标签: python pandas 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 个答案:

答案 0 :(得分:1)

您可以通过提供ax.set_yscale('log')

来使用对数y标度