Welcome to this lesson on matplotlib! As we just learned, matplotlib is a Python library used for making graphs. It’s commonly used by research scientists and data scientists, among other professionals. Matplotlib makes it easy to turn tabular data (data in a spreadsheet, table, or .csv) into basic visualizations.

In this lesson we will…

  • Learn about five basic chart types
  • Review the general structure of matplotlib code
  • Make a line chart to compare temperature data from around the world
  • Explore the line chart: change style options, adjust axes, and add title and legend

In the Jupyter notebook to the right, we’ll start by importing matplotlib.pyplot as plt, and importing a dataset of average monthly temperatures around the world.



Let’s practice running the first two Jupyter cells to load our packages and display the chart correctly.

  1. Select the code cell beginning # load matplotlib and pandas (click anywhere in the cell)
  2. Click the Run button or the Shift+Enter/Return keys (see image below)
  3. Click the Save button or use the Control/Command+S keys to save your work Screenshot of the buttons at the top of a Jupyter Notebook. The Run and Save buttons are highlighted
  4. Repeat this process for the cell that says # display charts correctly.
  5. Click the Test Work button below the Jupyter Notebook to check if you’ve completed the Checkpoint!

If you’ve successfully completed the Checkpoint, you’ll get a green check at the top of the checkpoint. When all checkpoints are complete, the Next button at the bottom right will become clickable.


We’ll need some data to get a data visualization going! We’re going to look at monthly average temperatures from around the world. Run the cell that says ## load in the data, then Save the notebook and click Test Work. Refer back to the steps in Checkpoint 1 if needed.


With our data loaded, let’s take a peek at what matplotlib can do. The next code block is all set up: still no need to type anything, just Run the cell that says # make a line chart, hit Save, then Test Work. Once you’re done, you can click Next to move on to the next exercise.

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?