Build a Temperature Line Chart
Intermediate · Write the code · from Matplotlib: Create Line, Bar, Scatter, and Pie Charts
From the lesson: Matplotlib: Create Line, Bar, Scatter, and Pie Charts
Imagine you have a spreadsheet with 10,000 rows of sales data. You could stare at those numbers for hours, or you could turn them into a chart and spot the trend in three seconds. That's the power of data visualization.
Read the lessonCreate a line chart showing daily temperatures. Use matplotlib.use('Agg') first, then create a figure with plt.subplots(). Plot the temperatures list against the days list. Set the title to 'Daily Temperatures', the x-label to 'Day', and the y-label to 'Temperature (F)'. Finally, print the title using ax.get_title().
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
temperatures = [72, 75, 68, 70, 78, 82, 79]
# Create figure and axes
# Plot the data
# Set title and labels
# Print the title
More Matplotlib exercises
- Build a Fruit Sales Bar ChartIntermediate
- Create a Height vs Weight Scatter PlotIntermediate
- Predict the Figure PropertiesIntermediate
- Fix the Broken LegendIntermediate
- Prepare Data for a Multi-Series ChartIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz