# -*- coding: utf-8 -*-
import seaborn as sns
import numpy as np
#------------------------显示中文---------------------------------#
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei'] # 指定默认字体
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
#----------------------------------绘制箱线图-----------------------------------#
'''
箱线图的作用:
检验连续数据是否存在离群点,以及数据分布的范围(4分位数)
必须要一个参数
y: 需要判断的数据序列
x: 分类的标签的数据
hue: 分组因子
palette: 调色板...Set1, Set2, Set3
linwidth: 线宽(2.5相当于加粗的线)
order: 排序的序列.例如 order = ['Dinner', 'Lunch']
orient = 'h' 对df中的每个数值型的数据都做一个箱线图
whis 参数设定是否显示箱线图的离群点, whis = np.inf 表示不显示
'''
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
tips
ax = sns.boxplot(x = 'time', y = 'total_bill',hue = 'smoker', data = tips, order = ['Dinner', 'Lunch'],
linewidth= 1.5,palette = 'Set3')
ax = sns.boxplot(data = tips, orient = 'h', palette = 'Set3')
#箱线图+ 有分布趋势的散点图
#图形组合也就是两条绘图语句一起运行就可以了,相当于图形覆盖了
ax = sns.boxplot(x='day', y = 'total_bill', data = tips)
ax = sns.swarmplot(x = 'day', y = 'total_bill', data = tips, color = '.25')
#plt.scatter(x = iris['sepal_length'], y = iris['sepal_width'])
#-----------------------------------barplot 带分布的散点图--------------------------#
'''
estimator: 统计参数默认为 np.mean,可自定义: np.sum, np.count_nonzero, np.median...
palette: 主题的颜色 palette = 'Blues_d'
'''
#统计参数默认实mean
ax = sns.barplot(x = "day", y = "total_bill", hue = 'sex', data = tips, estimator= np.sum