Visualizing with Multiple Line Graphs in Matplotlib

📊 Data Viz Beginner

Line graphs are a go-to for showing trends over time — but what if you have more than one set of data to compare? That's where multiple line graphs come in. In this tutorial, we'll walk you through how to create and customize multiple lines on a single graph using Python's Matplotlib library.

Why Use Multiple Line Graphs?

Multiple line graphs are perfect when you want to compare different data series over the same time period. For example, tracking temperatures in several cities, comparing website traffic across different sources, or seeing how various stocks are performing. Displaying them on the same graph makes it easier to spot patterns, differences, and trends.

What You'll Learn

Step-by-Step Code Example

Here's how to create a multiple line graph in Matplotlib — we're comparing match scores for Joe Root and Steve Smith across 30 games:

Python
import matplotlib.pyplot as plt
import numpy as np

Joe_Root = np.array([28, 62, 15, 110, 33, 8, 70, 92, 45, 60,
                     81, 39, 20, 75, 13, 18, 67, 41, 99, 50,
                     103, 58, 36, 61, 49, 88, 4, 10, 29, 73])

Steve_Smith = np.array([23, 55, 47, 29, 83, 17, 66, 87, 40, 34,
                        51, 27, 90, 63, 36, 31, 21, 60, 70, 44,
                        78, 69, 48, 57, 39, 74, 12, 97, 65, 26])

plt.figure(figsize=(10, 5))
x = np.arange(1, 31)

plt.plot(x, Joe_Root, label='Joe Root', color='#184452', marker='o')
plt.plot(x, Steve_Smith, label='Steve Smith', color='#77cce6', marker='o')

plt.title('Joe Root vs Steve Smith')
plt.xlabel('Matches', fontdict={'fontname': 'Comic Sans MS', 'fontsize': 15})
plt.ylabel('Scores', fontdict={'fontname': 'Comic Sans MS', 'fontsize': 15})

plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.grid(True, alpha=0.7, linestyle='--')
plt.show()

We've used two arrays — Steve_Smith and Joe_Root — with 30 match scores each (dummy data, don't take it too seriously).

Understanding the Code

Output:

Multiple line graph output Two lines, two players, one clean comparison.

When to Use Multiple Line Graphs

Mini Project: Track Your Favorite Players This Season

Ready to flex your Matplotlib skills and your sports obsession? Pick 2–3 of your favorite players from cricket, football, or basketball and track how they performed match by match.

This gives you a cool visual of who's been consistent, who had a comeback, and who's been ghosting.

Bonus points if you highlight best & worst games with annotations, or use a title like "Battle of the GOATs: 2025 Season Stats"