Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Seaborn · Function

pairplot

Creates a figure-level grid of pairwise relationships for numeric variables, with each variable’s marginal distribution on the diagonal. Grouping, variable selection, plot type, sizing, and triangular layouts can be configured.

How it works

pairplot builds a figure-level grid containing plots for combinations of numeric variables. Off-diagonal cells show relationships, diagonal cells show each variable’s marginal distribution, and options such as hue, kind, variable selectors, and corner control the layout and visual encoding.

Syntax

seaborn.pairplot(data, *, hue=None, hue_order=None, palette=None, vars=None, x_vars=None, y_vars=None, kind='scatter', diag_kind='auto', markers=None, height=2.5, aspect=1, corner=False, dropna=False, plot_kws=None, diag_kws=None, grid_kws=None, size=None)

Parameters

NameTypeDescription
dataDataFrameDataFrame containing the variables to plot.
huevector or key in data, optionalVariable used to group observations by a semantic mapping.
hue_orderlist, optionalOrder for the levels of the hue variable.
palettestring, list, dict, or callable, optionalColors used for the hue levels.
varslist of variable names, optionalVariables to use in both rows and columns.
x_varslist of variable names, optionalVariables to use on the x axes.
y_varslist of variable names, optionalVariables to use on the y axes.
kindstring, optionalOff-diagonal plot type: scatter, kde, hist, or reg.
diag_kindstring, optionalDiagonal plot type, selected automatically by default.
markerslist or boolean, optionalMarkers used for hue levels.
heightfloat, optionalHeight of each facet in inches.
aspectfloat, optionalAspect ratio of each facet.

Returns

A PairGrid instance containing the plotted axes.

Key points

  • Use pairplot to inspect many variable relationships in one figure.
  • Numeric variables organize the grid so each variable occupies a row and a column.
  • Diagonal cells summarize the marginal distribution of each variable.
  • Use vars to limit the plot to selected variables.
  • Use x_vars and y_vars when row and column selections should differ.
  • Choose among scatter, KDE, histogram, and regression styles with kind.

Common mistakes

  • Use PairGrid instead when the high-level defaults do not provide enough control over the grid or mappings.
  • The diagonal is not another pairwise relationship; it displays a univariate distribution for each variable.

Example: Pairwise relationships with a grouping variable

import seaborn as sns
import matplotlib.pyplot as plt

penguins = sns.load_dataset("penguins")
sns.pairplot(penguins, hue="species", vars=["bill_length_mm", "bill_depth_mm", "body_mass_g"])
plt.show()

Loads the example penguins dataset and compares selected numeric variables, coloring observations by species.

When to use it

Survey many numeric relationships

Exploratory analysis of a tabular dataset.

Inspect groups with hue

Comparing distributions across categories.

Select variables or use a corner layout

Reducing visual clutter in a large grid.

Interview questions

QWhat does pairplot generate?

The function creates a grid of pairwise relationship plots for the numeric variables in the dataset, with marginal distribution plots on the diagonal. It is a high-level interface to PairGrid for common styles.

Follow-up: When would you choose PairGrid instead? Choose it when more customization or control over the grid is required.

QHow does hue affect a pair plot?

hue assigns a variable for semantic grouping, so observations are distinguished by color or another palette mapping. hue_order controls the order of its levels, while palette controls their colors.

Follow-up: How can the plotted variables be restricted? Use vars for one shared selection, or x_vars and y_vars to specify row and column variables separately.

QHow can the plot style and layout be changed?

The kind parameter selects the off-diagonal plot style from scatter, kde, hist, or reg. The diagonal style is controlled independently by diag_kind, whose automatic behavior chooses an appropriate marginal plot.

Follow-up: How can a triangular grid be made? Set corner=True to omit the redundant upper-triangle plots.

  • PairGrid
  • scatterplot
  • kdeplot
  • histplot
  • regplot

Source: seaborn.pairplot — seaborn 0.13.2 documentation. Checked 2026-10-15.