python 条形图 负值_Matplotlib条形图x轴以下的负值

importmatplotlib.pyplotaspltplt.rcdefaults()importnumpyasnpimportmatplotlib.pyplotaspltobjects=('Python','C++','Java','Perl','Scala','Lisp')y_pos=np.arange(len(objects))performance=[10,8,6,-4,2,1]plt.bar(y_pos,performance,align='center',alpha=0.5)# Get the axes objectax=plt.gca()# remove the existing ticklabelsax.set_xticklabels([])# remove the extra tick on the negative barax.set_xticks([idxfor(idx,x)inenumerate(performance)ifx>0])ax.spines["bottom"].set_position(("data",0))ax.spines["top"].set_visible(False)ax.spines["right"].set_visible(False)# placing each of the x-axis labels individuallylabel_offset=0.5forlanguage,(x_position,y_position)inzip(objects,enumerate(performance)):ify_position>0:label_y=-label_offsetelse:label_y=y_position-label_offsetax.text(x_position,label_y,language,ha="center",va="top")# Placing the x-axis label, note the transformation into `Axes` co-ordinates# previously data co-ordinates for the x ticklabelsax.text(0.5,-0.05,"Usage",ha="center",va="top",transform=ax.transAxes)plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值