数据分布绘图

背景

数据分布绘图的代码

实验

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)

你可能感兴趣的:(人工智能,机器学习,大数据)