Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 37 ยท Collecting and Displaying Data

Stem-and-Leaf Diagrams and Line Graphs

Build stem-and-leaf diagrams with keys, back-to-back versions, and line graphs for data over time, including trend, seasonality and a moving average.

Two more displays complete your toolkit for this chapter. A stem-and-leaf diagram keeps every original value while showing the shape, which is ideal for small data sets. A line graph shows how a quantity changes over time.

Stem-and-leaf diagrams

Each value is split into a stem (all digits except the last) and a leaf (the last digit). Take these test scores:

34, 41, 45, 47, 52, 52, 55, 58, 61, 63, 67, 72, 75, 79, 88

Stem Leaf
3 4
4 1 5 7
5 2 2 5 8
6 1 3 7
7 2 5 9
8 8

Key: 4 | 5 means 45.

Rules:

  1. Write the stems in a column, in order, with no gaps in the sequence (include a stem even if it has no leaves).
  2. Write the leaves in increasing order along each row, one digit each, evenly spaced.
  3. Always include a key so readers know what the numbers mean.

The diagram is a histogram turned on its side, but you can still read every value. The median and quartiles are easy to find because the data are in order.

Python Generate a stem-and-leaf diagram

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Back-to-back diagrams

To compare two groups, put one group's leaves on the left (reading outward) and the other's on the right, sharing the stems. Both sides need a key.

Python Back-to-back comparison

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Group B's scores are tightly bunched in the 50s and 60s, while Group A is more spread out. You can see this from the shape alone.

Line graphs and time series

A time series is a set of values recorded at regular times, such as the daily temperature or monthly sales. A line graph plots them in time order and joins the points with lines. Time goes on the horizontal axis.

Things to look for:

  • Trend: the long-term direction (up, down, flat).
  • Seasonality: a pattern that repeats, such as higher ice-cream sales every summer.
  • Outliers: unusual points, perhaps from a one-off event.
Python A line graph of monthly rainfall (made-up data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Join the points with straight lines only when values between the recorded times make sense. For categories without order, a line graph is wrong; use a bar chart.

Smoothing with a moving average

A moving average replaces each value by the mean of itself and its neighbors, which smooths short-term jumps and reveals the trend. A 3-point moving average at position i is (x[i-1] + x[i] + x[i+1]) / 3.

Python 3-point moving average

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The smoothed line rises steadily, showing a clear upward trend even though sales zigzag from month to month. The first and last months have no 3-point average because they lack a neighbor.

Choosing the right display

Data and goal Good display
Categories, compare counts Bar chart
Parts of a whole Pie chart
Continuous data, shape Histogram
Small data set, keep every value Stem-and-leaf
Change over time Line graph

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a stem-and-leaf diagram with key 6 | 3 meaning 63, what does the entry 7 | 0 4 represent?

    The stem is the tens digit and each leaf is a units digit, so the values are 70 and 74.
  2. 2. Which display is best for monthly temperatures over three years?

    The data are recorded in time order, so a line graph shows the trend and seasonality.
  3. 3. Why must every stem-and-leaf diagram have a key?

    Without a key, 4 | 5 could mean 45, 4.5 or 450.
  4. 4. What does a moving average do to a time series?

    Averaging neighbors reduces random ups and downs.

Summary

  • Stem-and-leaf diagrams keep every value, show the shape and need a key; leaves are in increasing order.
  • Back-to-back versions compare two groups.
  • Line graphs show data over time, revealing trend, seasonality and outliers.
  • A moving average smooths a time series.

Next: Mean, Median and Mode