Open In App

How To Make Scatter Plot with Regression Line using Seaborn in Python?

In this article, we will learn how to male scatter plots with regression lines using Seaborn in Python. Let’s discuss some concepts :

Adding a regression curve to a scatterplot between two numerical variables is a good way to ascertain the linear trend. And we also will see an example of customizing the scatter plot with a regression curve.



Steps Required

Example 1: Using regplot() method

This method is used to plot data and a linear regression model fit. There are a number of mutually exclusive options for estimating the regression model.






# importing libraries
import seaborn as sb
  
# load data
df = sb.load_dataset('iris')
  
# use regplot
sb.regplot(x = "sepal_length",
            y = "petal_length"
            ci = None,
            data = df)

Output :

Example 2: Using lmplot() method

The lmplot is another most basic plot. It shows a line representing a linear regression model along with data points on the 2D-space and x and y can be set as the horizontal and vertical labels respectively.




# importing libraries
import seaborn as sb
  
# load data
df = sb.load_dataset('iris')
  
# use lmplot
sb.lmplot(x = "sepal_length",
            y = "petal_length"
            ci = None,
            data = df)

Output : 


Article Tags :