How to plot and interpret pairwise plots in python.

Cynthia Kuzira
3 min readDec 29, 2022

--

What are Pairwise plots?

Pairwise plots allow us to see both the distribution of a single variable and the relationship between two variables. They are a great method to identify follow-up analysis trends and help us select the best set of features to explain a relationship between two variables.

The pairwise plots by default plot only the numerical values, although later on, you can use the hue feature to plot categorical values, as we shall see in the blog.

How to plot Pairwise plots in Python

You will need to import the seaborn library. I am also using a real-life data set for marketing

First load the dataset

Image of data frame for the marketing dataset

To create a pairwise plot, we shall use this code

pairwise plot output

Interpretation

The first row at the bottom represents sales on the y-axis, then the middle one represents social media, and the one at the top represents radio on the y-axis. The first column on the left represents radio on the x-axis, the middle one social media, and the one on the far right sales.

So the scatter plots help us to determine the relationship between the different variables, and the histograms on the main diagonal axis show us the distribution of the individual variable.

For example, the first scatter plot on the bottom left shows that there is a positive linear relationship between sales and radio

Scatter plot of radio and sales

The next scatter plot in the middle shows that there is a linear relationship between social media and sales

scatter plot of social media and sales

The histogram on the bottom right shows the distribution of sales.

Adding the categorical variable TV, we use hue.

Pairwise plot with hue added to it

Advantages

It can be used to determine which features are useful for our classification.

Limitations

They can only be used when the variables to be plotted are few.

I hope you find this blog helpful😊

--

--

No responses yet