Login
📚 Python for Introductory Statistics
Chapters ▾

5.7 Scatter Plots

Watch demo video

A data set with a pair of quantitative variables can be displayed with a scatter plot.

Example: Age in years and the corresponding height in centimeters is given below. Draw a scatter plot.

age(yrs)Height(cm)
595
6100
7105
8107
9110
10115
  1. Click + Code
  2. Type import matplotlib.pyplot as plt
  3. Type x = [5,6,7,8,9,10]
  4. Type y = [95,100,105,107,110,115]
  5. Type plt.scatter(x,y)
  6. Type plt.suptitle('Scatter Plot Age vs Height')
  7. Type plt.xlabel('Age(yrs)')
  8. Type plt.ylabel('Height(cm)')
  9. Click play button
import matplotlib.pyplot as plt

x = [5,6,7,8,9,10]
y = [95,100,105,107,110,115]

plt.scatter(x,y)

plt.suptitle('Scatter Plot Age vs Height')
plt.xlabel('Age(yrs)')
plt.ylabel('Height(cm)')
Show expected output
Text(0, 0.5, 'Height(cm)')
Scatter plot titled Scatter Plot Age vs Height: six points rising steadily from (5, 95) to (10, 115); axes labeled Age(yrs) and Height(cm).

Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.