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
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
# 直方图
sns.distplot(x1, bins=20, kde=False, rug=True)
<matplotlib.axes._subplots.AxesSubplot at 0x20ec98f6898>
# 核密度估计
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
<matplotlib.axes._subplots.AxesSubplot at 0x20eca5c60f0>
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
<matplotlib.axes._subplots.AxesSubplot at 0x20ecbc52a58>
# 拟合参数分布
sns.distplot(x1, kde=False, fit=stats.gamma)
<matplotlib.axes._subplots.AxesSubplot at 0x20ecc2fe2b0>
# 双变量分布
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.axisgrid.JointGrid at 0x20ec4c9df28>
# 二维直方图
sns.jointplot(x="x", y="y", data=df_obj1, kind="hex");
# 核密度估计
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
# 数据集中变量间关系可视化
dataset = sns.load_dataset("tips")
#dataset = sns.load_dataset("iris")
sns.pairplot(dataset);
类别数据可视化
#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)
<matplotlib.axes._subplots.AxesSubplot at 0x20ece211e48>
sns.swarmplot(x="diet", y="pulse", data=exercise, hue='kind')
<matplotlib.axes._subplots.AxesSubplot at 0x20ece09bda0>
# 盒子图
sns.boxplot(x="diet", y="pulse", data=exercise)
#sns.boxplot(x="diet", y="pulse", data=exercise, hue='kind')
<matplotlib.axes._subplots.AxesSubplot at 0x20ece065828>
# 小提琴图
#sns.violinplot(x="diet", y="pulse", data=exercise)
sns.violinplot(x="diet", y="pulse", data=exercise, hue='kind')
<matplotlib.axes._subplots.AxesSubplot at 0x20ece0adb00>
# 柱状图
sns.barplot(x="diet", y="pulse", data=exercise, hue='kind')
<matplotlib.axes._subplots.AxesSubplot at 0x20ece0190f0>
# 点图
sns.pointplot(x="diet", y="pulse", data=exercise, hue='kind');