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!
Define three lists,
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!
x and display the plot.
On the same graph, plot
x (after the line where you plot
y1 line a
pink line and the
y2 line a
gray line. Give both lines round markers.
Give your graph a title of
“Two Lines on One Graph”, and label the x-axis
”Amazing X-axis” and y-axis
Give the graph a legend and put it in the lower right.
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.