Skip to main content

Line Charts

Learn how to use line charts to show how values change over time or across an ordered sequence.

Skill Level: Beginner
Prerequisites: Bar Charts
Estimated Time: 25 minutes

Story Time

In the previous lesson, you learned how bar charts help compare categories.

Now we move to a different kind of question: how do values change over time or across an ordered sequence?

This is where line charts become useful. In data analysis, we often want to study trends such as monthly sales, daily temperature, yearly population, or average scores across several test sessions.

In this lesson, you will learn how to create, read, and interpret line charts using Matplotlib.

Learning Objectives

By the end of this lesson, you will be able to:

  • explain when line charts should be used
  • create a basic line chart with Matplotlib
  • add titles, labels, and markers
  • interpret upward, downward, and fluctuating trends
  • distinguish line charts from bar charts
  • identify common mistakes when working with trend data
Why This Topic Matters

Many important analytical questions involve change. Line charts help you see whether values go up, down, stay flat, or fluctuate across time or sequence, which is essential for understanding trends.

What Is a Line Chart?

A line chart displays data as a series of points connected by lines.

Usually:

  • the x-axis shows time or an ordered sequence
  • the y-axis shows the measured value

Each point represents one observation, and the connecting line helps you see how the values move from one point to the next.

When Should You Use a Line Chart?

Use a line chart when your x-axis follows a meaningful order.

Common examples include:

  • days
  • weeks
  • months
  • years
  • test sessions
  • steps in a process

A line chart is best when you want to show trend. If the goal is to compare separate categories such as gender or lunch type, a bar chart is usually more appropriate.

Your First Line Chart

You can create a simple line chart with plt.plot().

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr"]
sales =

plt.plot(months, sales)
plt.show()

This chart connects the points in order, making it easier to see how the sales values change from month to month.

Understanding What the Line Chart Shows

In the example above:

  • sales increase from January to February
  • decrease slightly from February to March
  • then increase again from March to April

This means the trend is generally upward, but not perfectly smooth.

That is an important interpretation skill: a line chart often tells a story about direction, movement, and variation.

Loading interactive line chart…
Try This

Change the values list to create different trend shapes:

  • a steadily increasing trend,
  • a steadily decreasing trend,
  • a fluctuating trend that goes up and down. Then describe each trend in one sentence.

Adding a Title and Axis Labels

As with any chart, titles and labels make the visual easier to interpret.

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr"]
sales =

plt.plot(months, sales)
plt.title("Monthly Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.show()

Now the viewer can immediately understand what the chart represents.

Adding Markers

Markers make it easier to see each individual data point.

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr"]
sales =

plt.plot(months, sales, marker="o")
plt.title("Monthly Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.show()

Using markers is especially helpful when the number of points is small, because it makes each observation easier to identify.

Customizing a Line Chart

Matplotlib also allows you to customize the line color, style, and marker design.

import matplotlib.pyplot as plt;

months = ["Jan", "Feb", "Mar", "Apr"]
sales =

plt.plot(
months,
sales,
color="blue",
linestyle="--",
marker="o"
)
plt.title("Monthly Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.show()

In this chart:

  • color="blue" changes the line color
  • linestyle="--" creates a dashed line
  • marker="o" adds circular markers

These settings can improve clarity, but they should not distract from the trend itself.

Reading a Line Chart as an Analyst

When interpreting a line chart, ask:

  1. What does the x-axis represent?
  2. What does the y-axis measure?
  3. Is the trend going upward, downward, or staying flat?
  4. Are there sudden changes?
  5. Are there repeated ups and downs?
  6. What is the main takeaway in one sentence?

For example:

Sales show an overall increase from January to April, despite a small dip in March.

That interpretation is more useful than simply stating that the chart contains four points.

Example: Student Scores Across Test Sessions

Suppose a student takes four tests and you want to visualize the scores.

import matplotlib.pyplot as plt

tests =[1][2][3][4]
scores =

plt.plot(tests, scores, marker="o")
plt.title("Student Score Trend")
plt.xlabel("Test Number")
plt.ylabel("Score")
plt.show()

A good interpretation might be:

  • the student’s scores increase across the four tests
  • the improvement is steady
  • the chart suggests a positive trend in performance

Example: Fluctuating Trend

Not every line chart shows steady improvement.

import matplotlib.pyplot as plt

weeks =[2][3][4][5][1]
attendance =[6][7][8][9][10]

plt.plot(weeks, attendance, marker="o")
plt.title("Weekly Attendance")
plt.xlabel("Week")
plt.ylabel("Attendance")
plt.show()

This chart does not show a simple increase or decrease.

Instead, attendance fluctuates from week to week. A good interpretation would mention both the variation and the lack of a consistent trend.

Line Chart vs Bar Chart

Students often confuse line charts and bar charts, so it is important to know the difference.

Use a line chart when:

  • the x-axis is ordered
  • you want to show change or trend
  • you want to focus on movement across points

Use a bar chart when:

  • the x-axis contains separate categories
  • you want to compare groups
  • the order is not about continuous progression

For example:

  • average score by gender → bar chart
  • average score by month → line chart

Google Colab Activity

Create a simple line chart in Google Colab using a list of five ordered values.

Then improve the chart by:

  1. adding a title
  2. labeling both axes
  3. adding markers
  4. changing the line style or color

After creating the chart, write a short interpretation of the trend.

After completing the activity in Google Colab, mark it as complete below.

Practice Exercise

Create a line chart showing the average mathematics score across five study sessions.

Then answer:

  • Is the trend increasing, decreasing, or fluctuating?
  • Is the change steady or irregular?
  • What is the main takeaway from the chart?

Self Evaluation

Check Your Understanding

1. When is a line chart most useful?

2. Which Matplotlib function is commonly used to create a line chart?

3. What does a marker do in a line chart?

4. Which statement best describes a fluctuating trend?

5. Which chart is usually better for comparing gender categories?

Challenge Exercise

Imagine you are tracking the average quiz score of a class across six weeks.

Create a line chart that clearly shows the change over time.

Your chart should include:

  • a meaningful title
  • x-axis and y-axis labels
  • markers
  • a written interpretation that explains the overall pattern

The goal is to make the trend easy for another student to understand.

Common Mistakes

Using a Line Chart for Unordered Categories

Line charts work best when the x-axis has a logical order, such as time or sequence. If the categories are separate and unordered, a bar chart is usually better.

Forgetting to Label the Axes

Without clear labels, the viewer may not know what the line represents. Titles and axis labels are essential for interpretation.

Focusing Only on Individual Points

A line chart is valuable because it highlights the overall trend. Do not only read one point at a time; also look at the shape of the line.

Confusing Fluctuation with Overall Trend

A line may go up and down while still showing a general increase or decrease overall. Strong interpretation looks at both local changes and the bigger pattern.

Common Mistake

Do not use a line chart just because it looks smooth. Use it when the x-axis has a meaningful order and you care about the overall pattern across that sequence.

Key Takeaways

In this lesson, you learned how to:

  • use line charts to show change over time or sequence
  • create line charts with Matplotlib
  • add titles, labels, and markers
  • interpret upward, downward, and fluctuating patterns
  • choose between line charts and bar charts more effectively

Continue Your Journey

Next, you will learn Scatter Plots, which help you study relationships between two numerical variables.