Learn

Before we jump into making a line chart, let’s take a step back and learn about five common chart types in data visualization, and how we make them appear in matplotlib.

Each graph that can be made in matplotlib has a dedicated function. To change the graph type, we change which graph function we’re calling from plt. Here are five of the most commonly used charts and the functions we call to make them:

Chart type Chart code
Line chart plt.plot()
Scatter plot plt.scatter()
Bar chart plt.bar()
Pie chart plt.pie()
Histogram plt.hist()
  • line chart: shows continuous change, often used to measure change over time
  • scatterplot: uses position to show the relationship, or correlation, between two numeric values
  • bar chart: uses bar height to compare a measure between categorical variables
  • pie chart: shows us the breakdown of a whole into its parts
  • histogram: shows how one kind of data is distributed

As with any Python function, we’ll supply arguments for the parameters of the function, and those will determine what the final graph output looks like.

In this lesson, we’ll focus on line charts. By the end of this module, however, we’ll cover everything needed to make all five of these charts.

Want to see what all these charts look like? We’ll compare them in the Jupyter notebook to the right. The code is already written, so just follow the instructions below to run the cells and see the graphs appear.

Instructions

1.

The first cell will load the packages and import all the datasets you’ll need for these graphs. Run this cell first.

After that, simply Run each cell (or press Command/Ctrl + Enter) to see its graph appear. Take a minute to look at the code, and see if you can predict anything about how the graph will look or what will be included. There’s no coding required for this lesson, so you don’t have to Save your notebook or press Test Work. Once you’re done exploring this notebook, you can click Next at any time.

By the end of this lesson and the next one, you’ll be able to code every single line of matplotlib code in this notebook yourself!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?