数据可视化seaborn(countplot定制)

sns.countplot能显示该列数据值的统计分布,要再显示百分比,程序如下

def add_freq():
    ncount=len(train)
    ax2=ax.twinx()
    ax2.yaxis.tick_left()
    ax.yaxis.tick_right()
    ax.yaxis.set_label_position('right')
    ax2.yaxis.set_label_position('left')
    ax2.set_ylabel('Frequency [%]')
    for p in ax.patches:
        x=p.get_bbox().get_points()[:,0]
        y=p.get_bbox().get_points()[1,1]
        ax.annotate('{:.1f}%'.format(100.*y/ncount),(x.mean(),y),ha='center',va='bottom')
    ax2.set_ylim(0,100)
    ax2.grid(None)

ax=sns.countplot(x=train['SeriousDlqin2yrs'],palette='Set3')
#sns.set(font_scale=1.5)
#ax.set_ylim(top=150000)
#ax.set_xlabel(' ')
#ax.set_ylabel(' ')
#fig=plt.gcf()
#fig.set_size_inches(10,5)
#ax.set_ylim(top=160000)
add_freq()
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值