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>
# 核密度估計(jì)
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>
# 擬合參數(shù)分布
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");
# 核密度估計(jì)
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
# 數(shù)據(jù)集中變量間關(guān)系可視化
dataset = sns.load_dataset("tips")
#dataset = sns.load_dataset("iris")
sns.pairplot(dataset);
類別數(shù)據(jù)可視化
#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>
# 點(diǎn)圖
sns.pointplot(x="diet", y="pulse", data=exercise, hue='kind');