Scatter plot
A scatter plot shows each row as a dot so you can see relationships between two numeric columns.
In this page:
Syntax
df.plot.scatter(x="column1", y="column2", c="color", s=size)
Scatter plot
df.plot.scatter(x, y) draws one point per row. Use c for colour and s for size to add extra dimensions. Scatter plots reveal correlation, clusters and outliers.
Note:
df.corr() gives the numeric correlation to match what you see.
Example: Scatter plot
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({"hours": [1, 2, 3, 4, 5], "score": [52, 58, 65, 70, 78]})
ax = df.plot.scatter(x="hours", y="score")
print("points:", len(ax.collections[0].get_offsets()))
print("correlation:", round(df["hours"].corr(df["score"]), 3))
# Output:
# points: 5
# correlation: 0.998
Related Topics
Common Mistakes
- Plotting non-numeric columns
- Ignoring overplotting
- Reading correlation as causation
Chapter Summary
- scatter shows two numeric columns
- c and s add colour and size
- Reveals correlation
- Points are rows
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: