Scatter Plot
A scatter plot places one point per pair of values (x, y)(x, y), so you can see at a glance
whether two variables move together. McKinney uses this exact technique to check
relationships in economic data — for example, plotting the change in money supply
(m1m1) against the change in unemployment (unempunemp) to look for a pattern.
flowchart LR
A["Two numeric columns"] --> B["One point per row: (x, y)"]
B --> C{"Points trend together?"}
C -->|Up-right| D["Positive relationship"]
C -->|Down-right| E["Negative relationship"]
C -->|Scattered| F["Little/no relationship"]
Basic scatter plot
Scatter
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6, 7]
y = [50, 55, 65, 70, 75, 78, 85]
plt.figure(figsize=(7, 4))
plt.scatter(x, y)
plt.title("Hours vs score")
plt.xlabel("Hours")
plt.ylabel("Score")
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()Scatter
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6, 7]
y = [50, 55, 65, 70, 75, 78, 85]
plt.figure(figsize=(7, 4))
plt.scatter(x, y)
plt.title("Hours vs score")
plt.xlabel("Hours")
plt.ylabel("Score")
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()Handle overplotting
Use transparency:
Alpha
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(x, y, alpha=0.6)
plt.title("Scatter with alpha")
plt.tight_layout()
plt.show()Alpha
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(x, y, alpha=0.6)
plt.title("Scatter with alpha")
plt.tight_layout()
plt.show()Annotate points
Annotate
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(x, y)
plt.annotate("top", xy=(7, 85), xytext=(6, 88), arrowprops={"arrowstyle": "->"})
plt.title("Annotated scatter")
plt.tight_layout()
plt.show()Annotate
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
plt.scatter(x, y)
plt.annotate("top", xy=(7, 85), xytext=(6, 88), arrowprops={"arrowstyle": "->"})
plt.title("Annotated scatter")
plt.tight_layout()
plt.show()Visualize it
Each dot below is one (x, y)(x, y) observation — watch the cloud of points build up and
notice the upward trend:
🧪 Try It Yourself
Exercise 1 – Draw a scatter plot
Exercise 2 – Control transparency
Exercise 3 – Annotate a point
Next
Continue to Pie Chart to see how (and when) to show parts of a whole.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
