📜  Python – seaborn.lmplot() 方法

📅  最后修改于: 2022-05-13 01:55:16.686000             🧑  作者: Mango

Python – seaborn.lmplot() 方法

Seaborn是一个惊人的Python统计图形绘图可视化库。它提供了漂亮的默认样式和调色板,使统计图更具吸引力。它建立在 matplotlib 库之上,并且与 pandas 的数据结构紧密集成。

seaborn.Implot() 方法

seaborn.lmplot()方法用于在 FacetGrid 上绘制散点图。

注意:要下载提示数据集,请单击此处。

下面的例子说明了 seaborn 库的 lmplot() 方法。

示例 1:带有回归线的散点图(默认情况下)。

Python3
# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# scatter plot with regression
# line(by default)
sns.lmplot(x ='total_bill', y ='tip', data = df)
 
# Show the plot
plt.show()


Python3
# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# scatter plot without regression
# line.
sns.lmplot(x ='total_bill', y ='tip',
           fit_reg = False, data = df)
 
# Show the plot
plt.show()


Python3
# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# scatter plot using hue attribute
# for colouring out points
# according to the sex
sns.lmplot(x ='total_bill', y ='tip',
          fit_reg = False, hue = 'sex',
          data = df)
 
# Show the plot
plt.show()


输出 :

散点图

示例 2:没有回归线的散点图。

Python3

# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# scatter plot without regression
# line.
sns.lmplot(x ='total_bill', y ='tip',
           fit_reg = False, data = df)
 
# Show the plot
plt.show()

输出 :

散点图 2

示例 3:使用色调属性的散点图根据性别对点进行着色。

Python3

# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# scatter plot using hue attribute
# for colouring out points
# according to the sex
sns.lmplot(x ='total_bill', y ='tip',
          fit_reg = False, hue = 'sex',
          data = df)
 
# Show the plot
plt.show()

输出 :

彩色散点图