lmplot画回归图
2020-12-03 本文已影响0人
Chaweys
#coding=utf-8
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.read_csv("tips.csv")
print(df.head()) #默认查看前五行
'''
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
'''
print(df.isna().any())
sns.lmplot(x="total_bill",y="tip",data=df)
plt.show()
#去除回归线fit_reg=False
sns.lmplot(x="total_bill",y="tip",data=df,fit_reg=False)
plt.show()


#hue 对数据进一步进行二次分类:hue="sex"再以sex进行分类
sns.lmplot(x="total_bill",y="tip",data=df,fit_reg=False,hue="sex")
plt.show()

#col 在列维度上进行分类 col="sex"
sns.lmplot(x="total_bill",y="tip",data=df,fit_reg=False,hue="sex",col="sex")
plt.show()

#row 在行维度上进行分类 row="smoker"
sns.lmplot(x="total_bill",y="tip",data=df,fit_reg=False,hue="sex",col="sex",row="smoker")
plt.show()

#aspect 控制图的长宽比
sns.lmplot(x="total_bill",y="tip",data=df,fit_reg=False,hue="sex",col="sex",row="smoker",aspect=2)
plt.show()

#order 控制进行回归的幂次
#默认是幂次是1
sns.lmplot(x="total_bill",y="tip",data=df)
plt.show()
#order=4 指定回归幂次为4
sns.lmplot(x="total_bill",y="tip",data=df,order=4)
plt.show()