Learn

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 and label your plots better. These are the concepts you’ve seen in Matplotlib so far:

  • Creating a line graph from data
  • Changing the appearance of the line
  • Zooming in on different parts of the axis
  • Putting labels on titles and axes
  • Creating a more complex figure layout
  • Adding legends to graphs
  • Changing tick labels and positions
  • Saving what you’ve made

Moving on, we’ll learn how to make different kinds of plots (beyond line graphs!) in Matplotlib and how to choose between those plots when displaying data.

Let’s do a final round of practice with all of the cool plotting concepts you’ve learned so far!

Instructions

1.

Define three lists, x, y1, and y2 and fill them with integers. These numbers can be anything you want, but it would be neat to have them be actual metrics that you want to compare. This is a fun site you can look at to find example datasets to plot!

2.

Plot y1 vs x and display the plot.

3.

On the same graph, plot y2 vs x (after the line where you plot y1 vs x)

4.

Make the y1 line a pink line and the y2 line a gray line. Give both lines round markers.

5.

Give your graph a title of “Two Lines on One Graph”, and label the x-axis ”Amazing X-axis” and y-axis ”Incredible Y-axis”.

6.

Give the graph a legend and put it in the lower right.

7.

Good job! Feel free to continue playing around in this space. Maybe make some subplots and separate out the lines. Maybe practice with zooming in on certain parts of the graph or selecting certain x- or y-ticks to display. When you’re ready, run the code one last time and move on.

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?