📜  Python – seaborn.regplot() 方法

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

Python – seaborn.regplot() 方法

Seaborn是一个基于 matplotlib 的Python数据可视化库。它提供了一个用于绘制有吸引力和信息丰富的统计图形的高级界面。 Seaborn 帮助解决了 Matplotlib 面临的两大问题;问题是什么?

  • 默认 Matplotlib 参数
  • 使用数据框

随着 Seaborn 对 Matplotlib 的补充和扩展,学习曲线非常缓慢。如果您了解 Matplotlib,那么您已经完成了 Seaborn 的一半。

seaborn.regplot() :

此方法用于绘制数据和线性回归模型拟合。有许多相互排斥的选项可用于估计回归模型。欲了解更多信息,请点击此处。

下面是上述方法的实现:

示例 1:

Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("mpg")
  
# draw regplot
sns.regplot(x = "mpg", 
            y = "acceleration", 
            data = data)
  
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.


Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("titanic")
  
# draw regplot
sns.regplot(x = "age",
            y = "fare",
            data = data,
            dropna = True)
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.


Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("exercise")
  
# draw regplot
sns.regplot(x = "id",
            y = "pulse", 
            data = data)
  
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.


Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("attention")
  
# draw regplot
sns.regplot(x = "solutions",
            y = "score",
            data = data)
  
# show ther plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.


输出 :

示例 2:

Python3

# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("titanic")
  
# draw regplot
sns.regplot(x = "age",
            y = "fare",
            data = data,
            dropna = True)
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.

输出 :

示例 3:

Python3

# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("exercise")
  
# draw regplot
sns.regplot(x = "id",
            y = "pulse", 
            data = data)
  
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.

输出

示例 4:

Python3

# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("attention")
  
# draw regplot
sns.regplot(x = "solutions",
            y = "score",
            data = data)
  
# show ther plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.

输出 :