- Lab
- A Cloud Guru
Creating Graphs with Matplotlib
Matplotlib is a popular and powerful library for plotting out information using Python. Since Python often works with datasets, and visually representing data can help demonstrate points within data, it makes sense that there is a useful Python library for just that. In this hands-on lab, we'll utilize `matplotlib` to create graphs to display various pieces of information about Target stores opened in the United States. _Warning_: This is a lab designed as part of a professional-level course and is difficult. The lab asks you to accomplish something using methods and functionality of the `matplotlib` library that might not have been covered in lessons. To feel comfortable completing this lab, you'll want to know how to do the following: - Use Matplotlib. Watch the lessons in the "Using Matplotlib" section from this course. - Be comfortable reading the [matplotlib documentation](https://matplotlib.org/) to find new functions and methods to use to accomplish your goal.
Path Info
Table of Contents
-
Challenge
Install matplotlib
Please Note: Accessing VS Code Server in the browser will require a password. The password is system generated and will either be
24bdf4febea54a8579305316
or can be located on the host itself by logging in via SSH and viewing theconfig.yaml
file.cat ~/.config/code-server/config.yaml
Within VS Code Server, you will have the opportunity to use the Jupyter Notebook service to render graphs. It will ask you for a password on first use. There is no password; simply place your cursor in the prompt box and press Enter/Return.
Before we can use
matplotlib
to generate graphs, we'll need to make sure that it is installed. -
Challenge
Create a Bar Graph Showing Number of Stores by State
From within the
target_graphs.py
file, create a bar chart to display the number of Target stores in each state. It will be useful to useitertools.groupby
to collect the information based on the state. It will likely be necessary to change the font size of the axis ticks so that the state abbreviations don't overlap; this can be done withset_yticklabel
andset_xticklabel
(depending on how the graph is oriented.) -
Challenge
Create a Line Graph Showing New Stores Opened Each Year
From within the
target_graphs.py
file, create a line graph that plots the number of Target stores that were opened each year. A line graph works well for charting this because we can visualize the information without adding a new tick label to the axis for years. -
Challenge
Create a Line Graph Showing the Total Number of Target Stores Over Time
From within the
target_graphs.py
file, create a line graph that plots the total number of Target stores that are open over time. We'll need to calculate the total for each year by using the total from the previous year and adding the number of new stores opened in a given year.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.