Pair grid

Seaborn basics

1 min read

Published Oct 7 2025, updated Aug 17 2026


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.PairGrid() creates a matrix of subplots (like pairplot()) to show pairwise relationships between multiple variables.

It’s the lower-level, fully customisable version of sns.pairplot().
You can:

  • Control what kind of plot appears in each section (upper, lower, diagonal)
  • Add custom plots or transformations
  • Mix multiple plot types in one grid

Syntax:

sns.PairGrid(    data,    *,    vars=None,    x_vars=None,    y_vars=None,    hue=None,    palette=None,    hue_kws=None,    corner=False,    diag_sharey=True,    height=2.5,    aspect=1,    despine=True,    dropna=True,)

Parameters:

  • data = DataFrame containing the data
  • vars = List of variables to include (both x and y)
  • x_vars, y_vars = Separate lists for asymmetric grids
  • hue = Variable for colour grouping
  • palette = Colour palette for hue
  • corner = If True, show only lower triangle
  • height = Height (inches) of each subplot
  • aspect = Aspect ratio of each subplot
  • diag_sharey = Share y-axis across diagonal plots
  • despine = Remove spines for cleaner look




Add different plots to diagonal and off-diagonal

import seaborn as snsimport matplotlib.pyplot as plt​iris = sns.load_dataset("iris")​g = sns.PairGrid(iris, hue="species", palette="Set2")g.map_lower(sns.scatterplot)g.map_diag(sns.kdeplot, fill=True)g.map_upper(sns.kdeplot)g.add_legend()plt.show()

  • Lower triangle = scatterplots
  • Upper triangle = KDE contours
  • Diagonal = smoothed KDE of each variable
  • Adds legend automatically

seaborn pairgrid plot example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact