Matplotlib/Pandas中条形图的优化 [英] Optimization of Bar Plots in Matplotlib/Pandas

查看:122
本文介绍了Matplotlib/Pandas中条形图的优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

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()

给出以下输出图:

结果是绝对正确的,但是当前面的单个竖线"A"使所有其他竖线如此微小且毫无意义时,我并不满意.有什么方法可以优化我的图表,使"B"-"K"看起来更大吗?我心中的想法是以y轴为0-300,但从300到800为300..800的方式拆分图形.或任何其他建议,高度赞赏.谢谢你.

The result is absolutely correct but I am not satisfied when a single bar 'A' at the front makes all the other bars so tiny and meaningless. Is there any way to optimize my chart in such a way that, 'B'-'K' appear bigger?. The thought I have in my mind is to split the graph in such a way that y-axis is 0-300 but from 300 to 800 it is 300..800. Or any other advices are highly appreciated. Thank you.

推荐答案

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

这篇关于Matplotlib/Pandas中条形图的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆