Survey many numeric relationships
Exploratory analysis of a tabular dataset.
Seaborn · Function
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.
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.
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)| Name | Type | Description |
|---|---|---|
data | DataFrame | DataFrame containing the variables to plot. |
hue | vector or key in data, optional | Variable used to group observations by a semantic mapping. |
hue_order | list, optional | Order for the levels of the hue variable. |
palette | string, list, dict, or callable, optional | Colors used for the hue levels. |
vars | list of variable names, optional | Variables to use in both rows and columns. |
x_vars | list of variable names, optional | Variables to use on the x axes. |
y_vars | list of variable names, optional | Variables to use on the y axes. |
kind | string, optional | Off-diagonal plot type: scatter, kde, hist, or reg. |
diag_kind | string, optional | Diagonal plot type, selected automatically by default. |
markers | list or boolean, optional | Markers used for hue levels. |
height | float, optional | Height of each facet in inches. |
aspect | float, optional | Aspect ratio of each facet. |
A PairGrid instance containing the plotted axes.
pairplot to inspect many variable relationships in one figure.vars to limit the plot to selected variables.x_vars and y_vars when row and column selections should differ.kind.PairGrid instead when the high-level defaults do not provide enough control over the grid or mappings.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.
Exploratory analysis of a tabular dataset.
Comparing distributions across categories.
Reducing visual clutter in a large grid.
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.
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.
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.
PairGridscatterplotkdeplothistplotregplot