Plot guides › Chart types

Scatter matrix (pair plot)

A scatter matrix draws a scatter plot for every pair of columns, with each column's distribution on the diagonal. It's a quick first look at a new dataset.

Example scatter matrix (pair plot) made with matplotlib
Rendered from the code below, with example data.

When to use it

Ask for it in pltchat

Upload your file and type something like:

"pair plot of all numeric columns"

pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.

The matplotlib code

Self-contained with example data; swap in pd.read_csv(...) or pd.read_excel(...) for your own file.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix

rng = np.random.default_rng(14)
n = 200
x = rng.normal(0, 1, n)
df = pd.DataFrame({"x": x, "x²": x ** 2 + rng.normal(0, 0.3, n),
                   "2x": 2 * x + rng.normal(0, 0.5, n),
                   "noise": rng.normal(0, 1, n)})

scatter_matrix(df, figsize=(6, 6), diagonal="hist", alpha=0.5, s=10)
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots