代码:
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()
gave the following output graph:
结果绝对正确,但当前面的单个条“A”使所有其他条变得如此小且毫无意义时,我不满意。有没有什么方法可以优化我的图表,使“B”-“K”显得更大?我的想法是以y轴为0-300但从300到800为300..800的方式分割图表。或者任何其他建议都将受到高度赞赏。谢谢。