Pair plot

Seaborn basics

2 min read

Published Oct 7 2025


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.pairplot() creates a grid of scatterplots and histograms (or KDEs) for pairwise relationships between numeric variables in a dataset.

It’s one of Seaborn’s most powerful exploratory tools, showing how each variable:

  • correlates with others (scatterplots), and
  • distributes individually (histograms or density plots on the diagonal).

Syntax:

sns.pairplot(
    data,
    *,
    hue=None,
    vars=None,
    x_vars=None,
    y_vars=None,
    kind="scatter",
    diag_kind="auto",
    markers=None,
    palette=None,
    corner=False,
    plot_kws=None,
    diag_kws=None,
    grid_kws=None,
    height=2.5,
    aspect=1,
    dropna=True,
    context=None,
)

Parameters:

  • data = DataFrame with numeric columns
  • hue = Variable to colour-code data points by category
  • vars = List of variables to include (both x and y)
  • x_vars, y_vars = Lists of variables for x and y axes (for asymmetric grids)
  • kind = Plot type: "scatter" (default) or "kde"
  • diag_kind = Plot type on the diagonal: "auto", "hist", or "kde"
  • markers = Marker style for scatterplots
  • palette = Colour palette for hue categories
  • corner = If True, show only the lower triangle of plots
  • plot_kws, diag_kws, grid_kws = Keyword arguments for customising subplots
  • height = Height (in inches) of each subplot
  • aspect = Aspect ratio of each subplot
  • dropna = Whether to drop missing values
  • context = Set a plotting context (e.g., "talk", "notebook")




Basic example

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris)
plt.show()

Creates a scatterplot matrix for all numeric columns in iris. Diagonal = histograms of each variable. Off-diagonal = pairwise scatterplots.


seaborn pair plot basic example





Add hue (colour by category)

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, hue="species", palette="Set2")
plt.show()

Colours each species differently. Great for class separation or cluster analysis.


seaborn pair plot hue example





Use KDE instead of scatterplots

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, hue="species", kind="kde")
plt.show()

Shows smooth density contours instead of discrete points. Great for large datasets or overlapping points.


seaborn pair plot kde example





Change diagonal plot type

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, hue="species", diag_kind="kde")
plt.show()

Replaces histograms on the diagonal with KDE (smoothed density) curves.


seaborn pair plot diagonal kde example





Select specific variables

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, vars=["sepal_length", "sepal_width", "petal_length"], hue="species")
plt.show()

Only plots relationships among selected columns. Useful for focusing on variables of interest.


seaborn pair plot specifc variables example





Asymmetric grids (x_vars vs y_vars)

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(
    iris,
    x_vars=["sepal_length", "sepal_width", "petal_length"],
    y_vars=["sepal_width", "petal_width"],
    hue="species"
)
plt.show()

Creates a non-square grid — useful for comparing two sets of variables.


seaborn pair plot asymmetric kde example





Show only lower triangle (corner)

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, hue="species", corner=True)
plt.show()

Hides the upper triangle, reducing redundancy. Common in publications for clarity.


seaborn pair plot lower corner example





Change marker style

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, hue="species", markers=["o", "s", "D"])
plt.show()

Uses different marker shapes for each category in hue.


seaborn pair plot marker example





Pass custom plotting options

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(
    iris,
    hue="species",
    plot_kws={"alpha": 0.7, "s": 60, "edgecolor": "k"},
    diag_kws={"fill": True, "linewidth": 2}
)
plt.show()

Adds transparency, size, and edges to scatter points. Smooths and thickens KDEs/histograms on the diagonal.


seaborn pair plot custom example





Pairplot with regression lines

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

sns.pairplot(iris, kind="reg", hue="species")
plt.show()

Adds linear regression lines in each scatterplot. Equivalent to calling sns.lmplot() for every pair.


seaborn pair plot regression example

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact