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