Seaborn_一般绘图函数factorplot 和 FacetGrid

# (1)根据2个维度变量绘图,画出model_year和mpg的关系图

sns.factorplot(data=df, x="model_year", y="mpg")

Seaborn_一般绘图函数factorplot 和 FacetGrid_第1张图片

#通过添加kind参数,折线图改柱形图
sns.factorplot(data=df, x="model_year", y="mpg",kind="bar")

Seaborn_一般绘图函数factorplot 和 FacetGrid_第2张图片

#(2)可以按照第3个维度绘制不同的关系图
sns.factorplot(data=df, x="model_year", y="mpg", col="origin")

Seaborn_一般绘图函数factorplot 和 FacetGrid_第3张图片

#(3)各种不同的图
#柱形图,添加密度函数
g = sns.FacetGrid(df, col="origin")
g.map(sns.distplot, "mpg")

Seaborn_一般绘图函数factorplot 和 FacetGrid_第4张图片

#散点图
g = sns.FacetGrid(df, col="origin")

g.map(plt.scatter, "horsepower", "mpg")

Seaborn_一般绘图函数factorplot 和 FacetGrid_第5张图片




#添加线性回归线
plt.xlim(0, 250)

plt.ylim(0, 60)

Seaborn_一般绘图函数factorplot 和 FacetGrid_第6张图片

#KDE等高线
df['tons'] = (df.weight/2000).astype(int)
g = sns.FacetGrid(df, col="origin", row="tons")
g.map(sns.kdeplot, "horsepower", "mpg")
plt.xlim(0, 250)
plt.ylim(0, 60)

Seaborn_一般绘图函数factorplot 和 FacetGrid_第7张图片

你可能感兴趣的:(机器学习)