Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Pair Plot | Plotting with Seaborn
Ultimate Visualization with Python

bookPair Plot

Note
Definition

A pair plot visualizes pairwise relationships between all numeric variables in a dataset. Unlike a joint plot, it is not limited to two variables. It creates an NΓ—N grid of subplots, where N is the number of numeric columns in the DataFrame.

Pair plot example

Pair Plot Description

Each column in the grid shares the same x-axis variable, and each row shares the same y-axis. The diagonal displays histograms of individual variables, while off-diagonal cells show scatter plots.

Creating a Pair Plot

You can create one using seaborn.pairplot(). Its only required argument is data, which must be a DataFrame. Parameters like height and aspect set the size (in inches) of each subplot.

12345678910
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Creating a pair plot sns.pairplot(iris_df, height=2, aspect=0.8) plt.show()
copy

Hue

The hue parameter assigns colors based on a specified categorical column. This highlights group differences and, when used in classification datasets, shows how classes separate across variable pairs.

With hue set (e.g., to species), the scatter plots color points by class, and diagonal plots switch from histograms to KDE plots, making class distributions clearer.

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Ignoring warnings import warnings warnings.filterwarnings('ignore') # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Setting the hue parameter to 'species' sns.pairplot(iris_df, hue='species', height=2, aspect=0.8) plt.show()
copy

Changing Plot Kinds

You can customize both the main and diagonal plots.

  • kind controls the off-diagonal plots (default: 'scatter');
  • diag_kind controls the diagonal (histogram or KDE, often chosen automatically when hue is used).
12345678910
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Setting the kind parameter and diag_kind parameters sns.pairplot(iris_df, hue='species', kind='reg', diag_kind=None, height=2, aspect=0.8) plt.show()
copy

'scatter', 'kde', 'hist', 'reg' are possible values for the kind parameter.

diag_kind can be set to one of the following values:

  • 'auto';
  • 'hist';
  • 'kde';
  • None.

Everything is similar to the jointplot() function in this regard.

Note
Study More

Explore more in the pairplot() documentation.

Task

Swipe to start coding

  1. Use the correct function to create a pair plot.
  2. Set the data for the plot to be penguins_df via the first argument.
  3. Set 'sex' as the column which will map the plot aspects to different colors via specifying the second argument.
  4. Set the non-diagonal plots to have a regression line ('reg') via specifying the third argument.
  5. Set height to 2.
  6. Set aspect to 0.8.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 6
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

What does the `aspect` parameter do in `pairplot()`?

Can you explain the difference between `hist` and `kde` on the diagonal?

How does using `hue` affect the appearance of the pair plot?

close

Awesome!

Completion rate improved to 3.85

bookPair Plot

Swipe to show menu

Note
Definition

A pair plot visualizes pairwise relationships between all numeric variables in a dataset. Unlike a joint plot, it is not limited to two variables. It creates an NΓ—N grid of subplots, where N is the number of numeric columns in the DataFrame.

Pair plot example

Pair Plot Description

Each column in the grid shares the same x-axis variable, and each row shares the same y-axis. The diagonal displays histograms of individual variables, while off-diagonal cells show scatter plots.

Creating a Pair Plot

You can create one using seaborn.pairplot(). Its only required argument is data, which must be a DataFrame. Parameters like height and aspect set the size (in inches) of each subplot.

12345678910
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Creating a pair plot sns.pairplot(iris_df, height=2, aspect=0.8) plt.show()
copy

Hue

The hue parameter assigns colors based on a specified categorical column. This highlights group differences and, when used in classification datasets, shows how classes separate across variable pairs.

With hue set (e.g., to species), the scatter plots color points by class, and diagonal plots switch from histograms to KDE plots, making class distributions clearer.

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Ignoring warnings import warnings warnings.filterwarnings('ignore') # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Setting the hue parameter to 'species' sns.pairplot(iris_df, hue='species', height=2, aspect=0.8) plt.show()
copy

Changing Plot Kinds

You can customize both the main and diagonal plots.

  • kind controls the off-diagonal plots (default: 'scatter');
  • diag_kind controls the diagonal (histogram or KDE, often chosen automatically when hue is used).
12345678910
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris species iris_df = sns.load_dataset('iris') # Setting the kind parameter and diag_kind parameters sns.pairplot(iris_df, hue='species', kind='reg', diag_kind=None, height=2, aspect=0.8) plt.show()
copy

'scatter', 'kde', 'hist', 'reg' are possible values for the kind parameter.

diag_kind can be set to one of the following values:

  • 'auto';
  • 'hist';
  • 'kde';
  • None.

Everything is similar to the jointplot() function in this regard.

Note
Study More

Explore more in the pairplot() documentation.

Task

Swipe to start coding

  1. Use the correct function to create a pair plot.
  2. Set the data for the plot to be penguins_df via the first argument.
  3. Set 'sex' as the column which will map the plot aspects to different colors via specifying the second argument.
  4. Set the non-diagonal plots to have a regression line ('reg') via specifying the third argument.
  5. Set height to 2.
  6. Set aspect to 0.8.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 6
single

single

some-alt