Seaborn Multi-Plot Grids
π² pairplot β every variable vs every other
sns.pairplot(df) # all numeric columns, scatter + histogram on diagonal
sns.pairplot(df, hue="species") # color by category
sns.pairplot(df, vars=["col1", "col2", "col3"]) # limit to specific columns
sns.pairplot(df, diag_kind="kde") # KDE instead of histogram on the diagonal
sns.pairplot(df, kind="reg") # regression line in off-diagonal cells
sns.pairplot(df, corner=True) # only lower triangle (skip redundant mirror)
pairplotis usually the fastest first step in exploratory analysis β one call reveals every pairwise relationship + each variable's distribution at once.
π― jointplot β two variables + their individual distributions
sns.jointplot(data=df, x="total_bill", y="tip")
sns.jointplot(data=df, x="total_bill", y="tip", kind="scatter") # default
sns.jointplot(data=df, x="total_bill", y="tip", kind="hex") # hexbin, good for dense data
sns.jointplot(data=df, x="total_bill", y="tip", kind="kde") # 2D density
sns.jointplot(data=df, x="total_bill", y="tip", kind="reg") # scatter + regression line
sns.jointplot(data=df, x="total_bill", y="tip", hue="time") # color by categoryShows a central scatter/density plot + marginal histograms on the top and right edges.
π§© FacetGrid β manual, flexible faceting
g = sns.FacetGrid(df, col="time", row="sex", hue="smoker")
g.map(sns.scatterplot, "total_bill", "tip")
g.add_legend()g = sns.FacetGrid(df, col="day", col_wrap=2, height=3)
g.map_dataframe(sns.histplot, x="total_bill") # map_dataframe passes the actual sub-DataFrame, not raw arraysReach for
FacetGriddirectly when a figure-level function (relplot/catplot/displot) doesn't support the exact plot type you need β those are actually built on top ofFacetGridinternally.
| Method | Passes to the plotting function |
|---|---|
.map(func, "x", "y") | positional arrays |
.map_dataframe(func, x="x", y="y") | keyword args + the facetβs own sub-DataFrame |
π PairGrid β manual version of pairplot
g = sns.PairGrid(df, hue="species")
g.map_diag(sns.histplot)
g.map_offdiag(sns.scatterplot)
g.add_legend()g = sns.PairGrid(df)
g.map_upper(sns.scatterplot)
g.map_lower(sns.kdeplot)
g.map_diag(sns.histplot)
PairGridlets you use a DIFFERENT plot type for upper triangle, lower triangle, and diagonal βpairplotcan't do that mix in one call.
π― JointGrid β manual version of jointplot
g = sns.JointGrid(data=df, x="total_bill", y="tip")
g.plot(sns.scatterplot, sns.histplot)π Next
Seaborn Styling & Themes Β· Seaborn Statistical Estimation & Data Handling