Visualizing time series

Intermediate

Introduction

Much of the data people chart is a time series: prices, visitors, temperatures, cases of an illness. Line charts are the natural choice, but time brings its own pitfalls: uneven spacing, missing dates silently bridged, series of very different sizes, and growth that looks explosive or flat depending on the axis. This lesson covers how to show change over time honestly.

How it works

Time on the x axis, evenly spaced. Time goes left to right, and equal distances must mean equal durations. If data were collected in 2010, 2015, 2016 and 2017, placing the four points evenly makes the first five years look like one. Plotting real dates fixes this.

Gaps. When days or months are missing, a line drawn straight across them invents values. Fill the calendar first, mark the missing periods, and let the line break. In pandas, reindexing to a full date range and leaving NaN does this, and plotting libraries break lines at NaN.

Indexing to 100. A large shop growing from 200 to 260 and a small one from 20 to 30 cannot be compared on one linear axis: the small shop is a flat line near the bottom. Indexing each series to 100 at the start (value ÷ first × 100) puts both on the same footing: the large shop reaches 130, the small one 150, so the small one grew faster.

Growth rates. Period-over-period growth is (new − old) ÷ old. Over several periods, the compound annual growth rate (or compound growth per period) is (last ÷ first)^(1 ÷ number of periods) − 1; it is not the average of the growth rates. At a constant growth rate g, the value doubles every ln 2 ÷ ln(1 + g) periods, about 7.3 periods at 10%.

Log scales. Constant percentage growth curves upwards ever more steeply on a linear axis, and makes early values unreadable. On a log scale, equal distances mean equal ratios (1, 10, 100, 1000), so constant growth is a straight line and a change in the growth rate shows as a bend. Always label log axes clearly, because many readers assume linear.

Choosing the period. Show enough history for context: a one-month view of a seasonal business can mislead. Mark the start and end dates in the title or axis.

Example

# Two series on different scales, compared by indexing both to 100 at the start.
months = ["Jan", "Feb", "Mar", "Apr"]
shop_a = [200, 210, 230, 260]       # large shop
shop_b = [20, 24, 28, 30]           # small shop
for name, values in [("A", shop_a), ("B", shop_b)]:
    indexed = [round(v / values[0] * 100, 1) for v in values]
    growth = [round((b - a) / a * 100, 1) for a, b in zip(values, values[1:])]
    print(name, "indexed:", indexed, " monthly growth %:", growth)
Open in compiler

Line by line

  1. Two shops with very different sales levels.
  2. Dividing by the first value and multiplying by 100 indexes each series.
  3. Monthly growth compares each month with the previous one.

Expected result

A indexed: [100.0, 105.0, 115.0, 130.0]  monthly growth %: [5.0, 9.5, 13.0]
B indexed: [100.0, 120.0, 140.0, 150.0]  monthly growth %: [20.0, 16.7, 7.1]

Indexed, the small shop clearly grew faster (to 150 against 130), which raw values on one axis would hide.

In the real world

Stock charts are often indexed to compare companies, and long-run charts of prices or populations use log scales. Public health dashboards show daily values with a 7-day average and mark days with missing reports. Economists report CAGR over decades rather than year-by-year swings.

Common mistakes

  • Evenly spacing irregular dates, which distorts the time axis.
  • Joining lines across missing periods.
  • Comparing raw series of very different sizes on one linear axis.
  • Averaging yearly growth rates instead of computing the compound rate.

Best practices

  • Use a real date axis and show gaps.
  • Index to 100 when comparing growth; say which date is the base.
  • Use a log scale for long periods of growth, and label it.

Summary

Time series need an evenly scaled time axis and visible gaps. Indexing to 100 compares growth across sizes, the compound growth rate summarises growth over many periods, and log scales turn constant growth into straight lines.

Quick check

1. A series goes 50, 60, 75. Indexed to 100 it becomes…
2. On a log axis, constant 10% growth appears as…
3. Sales grow from 100 to 121 in two years. The compound annual growth rate is…
4. Three days of data are missing. What should a line chart do?

Key takeaways

  • Space time evenly and show missing periods as gaps.
  • Index series to 100 to compare growth across different sizes.
  • Constant percentage growth is a curve on a linear axis and a straight line on a log axis.

Practice problems for this lesson

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.