Visualizing Relationship between variables with scatter plots in Seaborn
Last Updated :
29 Aug, 2020
Improve
To understand how variables in a dataset are related to one another and how that relationship is dependent on other variables, we perform statistical analysis. This Statistical analysis helps to visualize the trends and identify various patterns in the dataset. One of the functions which can be used to get the relationship between two variables in Seaborn is relplot()
.
Relplot() combines FacetGrid with either of the two axes-level functions scatterplot() and lineplot(). Scatterplot is default kind of relplot(). Using this we can visualize joint distribution of two variables through a cloud of points. We can draw scatterplot in seaborn using various ways. The most common one is when both the variables are numeric.
Example: Let's take an example of a dataset that consists a data of CO2 emissions of different vehicles. To get the dataset click here.# import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# set grid style
sns.set(style ="darkgrid")
# import dataset
dataset = pd.read_csv('FuelConsumption.csv')
sns.relplot(x ="ENGINESIZE", y ="CO2EMISSIONS",
data = dataset);

sns.relplot(x ="ENGINESIZE", y ="CO2EMISSIONS",
hue ="FUELTYPE", data = dataset);

sns.relplot(x ="ENGINESIZE", y ="CO2EMISSIONS",
hue ="FUELTYPE", style ="FUELTYPE",
data = dataset);

sns.relplot(x ="ENGINESIZE", y ="CO2EMISSIONS",
hue ="CYLINDERS", data = dataset);

sns.relplot(x ="ENGINESIZE", y ="CO2EMISSIONS",
size ="CYLINDERS", data = dataset);
