数据分布绘图

背景

数据分布绘图的代码

实验

data_test["ec"] = data_test["折扣"]

import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
# 解决负号'-'显示为方块的问题
plt.rcParams['axes.unicode_minus'] = False
fig = plt.figure(figsize=(12,3))
font = {
        'size' :15.5,
        'family':'SimHei',
        }
matplotlib.rc('font', **font)
ax1 = fig.add_subplot(1,2,1)
fig.subplots_adjust(left=0.0,bottom=0.0,top=1,right=1)
def autolabel(rects, hs):
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x()+rect.get_width()/2.-0.11, hs, '%s' % round(height,2), size=13.5, family="Times new roman")
        
desc = abs(data_test["ec"]).describe()
y = [desc["min"], desc["mean"], desc["max"], desc["25%"], desc["50%"], desc["75%"]]
index = [0,1,2,3,4,5]
widths = 0.25
xticks=["","min","mean","max","25%","50%","75%"]
for i in range(len(index)):
    axb = ax1.bar(i, width=widths, height=y[i],color="#cea2fd")
    autolabel(axb,y[i])
ax1.set_xticklabels(xticks)
ax1.set_xlabel('指标')
ax1.set_ylabel('折扣')

ax2 = fig.add_subplot(1,2,2)
# #099DD9
# #cea2fd
# turquoise
sns.distplot(abs(data_test["ec"].dropna()), ax=ax2, color="#cea2fd",kde_kws={"color":"#cea2fd", "lw" :1 })
ax2.set_xlabel('折扣')
ax2.set_ylabel('分布值')
fig.tight_layout(pad=0.6)
fig.savefig("t.png", format='png', dpi=150)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值