Introduction to Matplotlib

Master a commonly used Python graphing module, Matplotlib. Soon, you will be producing high-quality plots to visualize your data.

Start[missing "en.views.course_landing_page.data-visualization-python.course_illustration" translation]
Chevron Left Icon
Line Graphs in Matplotlib
Lesson 1 of 3
Chevron Right Icon
  1. 1

    Matplotlib is a Python library used to create charts and graphs. In this first lesson, you will get an overview of the basic commands necessary to build and label a line graph. The concepts you wi...

  2. 2

    Line graphs are helpful for visualizing how a variable changes over time. Some possible data that would be displayed with a line graph: average prices of gasoline over the past decade weight o...

  3. 3

    We can also have multiple line plots displayed on the same set of axes. This can be very useful if we want to compare two datasets with the same scale and axis categories. Matplotlib will automati...

  4. 4

    We can specify a different color for a line by using the keyword [...] with either an HTML color name or a HEX code : [...] ![money_colors](https://s3.amazonaws.com/codecademy-content/cours...

  5. 5

    Sometimes, it can be helpful to zoom in or out of the plot, especially if there is some detail we want to address. To zoom, we can use [...] . We use [...] by feeding it a list as input. This li...

  6. 6

    Eventually, we will want to show these plots to other people to convince them of important trends in our data. When we do that, we’ll want to make our plots look as professional as possible. The...

  7. 7

    Sometimes, we want to display two lines side-by-side, rather than in the same set of x- and y-axes. When we have multiple axes in the same picture, we call each set of axes a subplot. The pictu...

  8. 8

    Sometimes, when we're putting multiple subplots together, some elements can overlap and make the figure unreadable: ![overlapping](https://s3.amazonaws.com/codecademy-content/courses/matplotlib/ov...

  9. 9

    When we have multiple lines on a single graph we can label them by using the command [...] . The [...] method takes a list with the labels to display. So, for example, we can call: [...] wh...

  10. 10

    In all of our previous exercises, our commands have started with [...] . In order to modify tick marks, we'll have to try something a little bit different. Because our plots can have multiple su...

  11. 11

    When we're making lots of plots, it's easy to end up with lines that have been plotted and not displayed. If we’re not careful, these "forgotten" lines will show up in your new plots. In order to b...

  12. 12

    Now you’ve played around with several two-dimensional line plots in Matplotlib. You’ve seen how you can create simple, readable plots with few commands. You’ve also learned some commands to style a...

  1. 1

    In the previous lesson, you learned how to create and label a line plot using Matplotlib! In this lesson, you'll learn how to create and when to use different types of plots: * Compare categories...

  2. 2

    The [...] function allows you to create simple bar charts to compare multiple categories of data. Some possible data that would be displayed with a bar chart: * x-axis — famous buildings, ...

  3. 3

    When we create a bar chart, we want each bar to be meaningful and correspond to a category of data. In the [...] chart from the last exercise, we could see that sales were different for different...

  4. 4

    We can use a bar chart to compare two sets of data with the same types of axis values. To do this, we plot two sets of bars next to each other, so that the values of each category can be compared. ...

  5. 5

    If we want to compare two sets of data while preserving knowledge of the total between them, we can also stack the bars instead of putting them side by side. For instance, if someone was plotting t...

  6. 6

    In the previous exercise, you learned to represent data as bars of different heights. Sometimes, we need to visually communicate some sort of uncertainty in the heights of those bars. Here are so...

  7. 7

    We’ve learned how to display errors on bar charts using error bars. Let’s take a look at how we might do this in an aesthetically pleasing way on line graphs. In Matplotlib, we can use [...] to ...

  8. 8

    If we want to display elements of a data set as proportions of a whole, we can use a pie chart. Pie charts are helpful for displaying data like: * Different ethnicities that make up a school distr...

  9. 9

    We also want to be able to understand what each slice of the pie represents. To do this, we can either: 1. use a legend to label each color, or 2. put labels on the chart itself. #### Method 1 ...

  10. 10

    Sometimes we want to get a feel for a large dataset with many samples beyond knowing just the basic metrics of mean, median, or standard deviation. To get more of an intuitive sense for a dataset, ...

  11. 11

    If we want to compare two different distributions, we can put multiple histograms on the same plot. This could be useful, for example, in comparing the heights of a bunch of men and the heights of ...

  12. 12

    In helping MatplotSip visualize their data, you’ve learned a bunch of new plot types that you can use in Matplotlib. Congratulations on adding these new plotting abilities to your repertoire: * Ho...

  1. 1

    Let's imagine that you are working as a high school math teacher. You want to display important metrics about your current class and the ones you have taught in previous years, in order to understa...

  2. 2

    First, we are going to look at the chart called [...] . bar_chart The data you will need to recreate t...

  3. 3

    Now, we are going to look at the chart called [...] . This displays the differences in average test scores between students who went to two different middle schools before enrolling in your high s...

  4. 4

    Now, we are going to look at the chart called [...] . This graph displays the breakdown of students who got As, Bs, Cs, Ds, and Fs in each unit. ![stacked](https://s3.amazonaws.com/codecademy-con...

  5. 5

    Now, we are going to look at the chart called [...] . This displays the breakdown of final exam scores between your first year of teaching vs your second year of teaching. ![histogram](https://s3...

  6. 6

    Now, we are going to look at the chart called [...] . This displays what students think the hardest topic covered throughout your math course is. ![pie](https://s3.amazonaws.com/codecademy-conten...

  7. 7

    Now, we are going to look at the chart called [...] . This displays the relationship between the time students say they studied and the scores they received on their final exams. ![fill_between](...

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Introduction to Matplotlib

Start[missing "en.views.course_landing_page.data-visualization-python.course_illustration" translation]