Seaborn简介

Seaborn

import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
  • 数据集分布可视化
# 单变量分布
x1 = np.random.normal(size=1000)
sns.distplot(x1);
C:\Program Files\Anaconda2\envs\py35\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
Seaborn简介_第1张图片
output_3_1.png
x2 = np.random.randint(0, 100, 500)
sns.distplot(x2);
C:\Program Files\Anaconda2\envs\py35\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
Seaborn简介_第2张图片
output_4_1.png
# 直方图
sns.distplot(x1, bins=20, kde=False, rug=True)

Seaborn简介_第3张图片
output_5_1.png
# 核密度估计
sns.distplot(x2, hist=False, rug=True)
C:\Program Files\Anaconda2\envs\py35\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j






Seaborn简介_第4张图片
output_6_2.png
sns.kdeplot(x2, shade=True)
sns.rugplot(x2)
C:\Program Files\Anaconda2\envs\py35\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j






Seaborn简介_第5张图片
output_7_2.png
# 拟合参数分布
sns.distplot(x1, kde=False, fit=stats.gamma)

Seaborn简介_第6张图片
output_8_1.png
# 双变量分布
df_obj1 = pd.DataFrame({"x": np.random.randn(500),
                   "y": np.random.randn(500)})

df_obj2 = pd.DataFrame({"x": np.random.randn(500),
                   "y": np.random.randint(0, 100, 500)})
# 散布图
sns.jointplot(x="x", y="y", data=df_obj1)

Seaborn简介_第7张图片
output_10_1.png
# 二维直方图
sns.jointplot(x="x", y="y", data=df_obj1, kind="hex");
Seaborn简介_第8张图片
output_11_0.png
# 核密度估计
sns.jointplot(x="x", y="y", data=df_obj1, kind="kde");
C:\Program Files\Anaconda2\envs\py35\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
Seaborn简介_第9张图片
output_12_1.png
# 数据集中变量间关系可视化
dataset = sns.load_dataset("tips")
#dataset = sns.load_dataset("iris")
sns.pairplot(dataset);
Seaborn简介_第10张图片
output_13_0.png

类别数据可视化

#titanic = sns.load_dataset('titanic')
#planets = sns.load_dataset('planets')
#flights = sns.load_dataset('flights')
#iris = sns.load_dataset('iris')
exercise = sns.load_dataset('exercise')
  • 类别散布图
sns.stripplot(x="diet", y="pulse", data=exercise)

Seaborn简介_第11张图片
output_17_1.png
sns.swarmplot(x="diet", y="pulse", data=exercise, hue='kind')

Seaborn简介_第12张图片
output_18_1.png
  • 类别内数据分布
# 盒子图
sns.boxplot(x="diet", y="pulse", data=exercise)
#sns.boxplot(x="diet", y="pulse", data=exercise, hue='kind')

Seaborn简介_第13张图片
output_20_1.png
# 小提琴图
#sns.violinplot(x="diet", y="pulse", data=exercise)
sns.violinplot(x="diet", y="pulse", data=exercise, hue='kind')

Seaborn简介_第14张图片
output_21_1.png
  • 类别内统计图
# 柱状图
sns.barplot(x="diet", y="pulse", data=exercise, hue='kind')

Seaborn简介_第15张图片
output_23_1.png
# 点图
sns.pointplot(x="diet", y="pulse", data=exercise, hue='kind');
Seaborn简介_第16张图片
output_24_0.png

你可能感兴趣的:(Seaborn简介)