Plot guides › Chart types

Scatter plot

A scatter plot puts one numeric variable on each axis and draws a point per row. It shows correlation, clusters and outliers at a glance; colour or marker size can add a third variable.

Example scatter plot made with matplotlib
Rendered from the code below, with example data.

When to use it

Watch out: With tens of thousands of points the plot becomes a blob. Use transparency, a hexbin plot or a 2D histogram.

Ask for it in pltchat

Upload your file and type something like:

"scatter of price vs area, colored by bedrooms"

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

rng = np.random.default_rng(2)
n = 200
area = rng.uniform(40, 200, n)
bedrooms = np.clip((area / 40).round() + rng.integers(-1, 2, n), 1, 6)
df = pd.DataFrame({"area": area, "bedrooms": bedrooms,
                   "price": 2.5 * area + 20 * bedrooms + rng.normal(0, 40, n)})

fig, ax = plt.subplots(figsize=(6.4, 4))
sc = ax.scatter(df["area"], df["price"], c=df["bedrooms"],
                cmap="viridis", s=25, alpha=0.8)
fig.colorbar(sc, ax=ax, label="Bedrooms")
ax.set_xlabel("Area (m²)")
ax.set_ylabel("Price (k$)")
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