Chp8-1
2019 年 12 月 23 日
In [34]: import pandas as pd import numpy as np from matplotlib import pyplot as plt import seaborn as sns %matplotlib inline df=pd.read_csv('C:\Python\Scripts\my_data\iris.csv',header=None, names=['sepal_length','sepal_width','petal_length','petal_width',' target']) my_data=df[['sepal_length','sepal_width']].iloc[:50] sns.lmplot(x='sepal_length',y='sepal_width',data=my_data,ci=None) #order 默认为 1,线性拟合 Out[34]: <seaborn.axisgrid.FacetGrid at 0x1b1dba2fa58>
In [41]: my_data['sample']=np.random.randint(1,3,len(my_data)) my_data.head() Out[41]: sepal_length sepal_width sample 0 5.1 3.5 1 1 4.9 3.0 2 2 4.7 3.2 1 3 4.6 3.1 1 4 5.0 3.6 1 In [24]: my_data.groupby('sample')[['sepal_length','sepal_width']].mean() Out[24]: sepal_length sepal_width sample 1 4.988889 3.366667 2 5.015625 3.446875 In [42]: sns.lmplot(x='sepal_length',y='sepal_width',data=my_data,ci=None,hue='sample') Out[42]: <seaborn.axisgrid.FacetGrid at 0x1b1dcc0cb70>
In [59]: sns.lmplot(x='sepal_length',y='sepal_width',data=my_data,ci=None,hue='sample', order=6) plt.ylim(2.5,4.5) Out[59]: (2.5, 4.5)
In [31]: sns.lmplot(x='sepal_length',y='sepal_width',data=my_data,ci=None,hue='sample', order=2) Out[31]: <seaborn.axisgrid.FacetGrid at 0x1b1db96b7f0>