seaborn可视化NOTE
#作图matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
plt.rcParams['axes.unicode_minus'] = False #显示负数
import seaborn as sns
#常规
sns.set_style('whitegrid')
sns.set_context('poster')
plt.figure(figsize = (8 ,5))
plt.xlabel('年份')
plt.ylabel('入会人数')
plt.title('各年份会员入会人数')
plt.xlim(0, 10)
plt.show()
#共轴
fig, ax1 = plt.subplots()
ax1 = sns.distplot(df['cost'],color = 'red',label='cost')
ax2 = sns.distplot(df['cost_baidu'],color = 'blue',label='bd')
ax2 = ax1.twinx()
#直方图、分布图
plt.hist(df['order_status'], bins='auto', color='#0504aa')
sns.countplot(df['order_status']) #count
sns.kdeplot(df['order_status']) #distribution
sns.distplot(df['order_status']) #count+distribution
#相关分析 kind = scatter,reg,resid,kde,等
sns.jointplot(x='order_status', y='total_distance', data=df,kind='reg')
#回归分析
sns.lmplot(x='order_status', y='total_distance', data=df)
#组合关系分析
sns.pairplot(df)
grids = sns.PairGrid(df_5)
grids.map_diag(sns.distplot)
grids.map_upper(sns.kdeplot)
grids.map_lower(plt.scatter)
#箱图
sns.boxplot(df['AGE'],orient = 'h')
#小提琴图
sns.violinplot(x='order_status', y='total_distance', data=df)
#分类柱状统计图
sns.barplot(x='order_status', y='total_distance', data=df)
#热力图
df_corr = df.corr()
sns.heatmap(df_corr, annot=True, vmax=1, square=True, cmap='Blues')
sns.jointplot(x="start_longitude", y="start_latitude", data=df, kind="kde")
#饼图
plt.pie([male, female], labels=['男','女'],
colors=['lightskyblue', 'lightcoral'],autopct='%1.1f%%')
#累积分布图
import numpy as np
from scipy import stats
density = stats.kde.gaussian_kde(df['x'])
bins = np.arange(-50,50,1)
plt.subplot(211)
plt.plot(bins,density(bins))
plt.subplot(212)
plt.plot(bins,density(bins).cumsum())