Editor

Build a Fruit Sales Bar 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 lesson

Create a bar chart showing fruit sales. Plot fruits on the x-axis and sales on the y-axis using ax.bar(). Set the title to 'Fruit Sales'. Print the number of bars using len(ax.patches) and print the height of the tallest bar.

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fruits = ['Apples', 'Bananas', 'Cherries', 'Dates']
sales = [150, 200, 80, 120]
# Create figure, plot bars, set title
# Print number of bars
# Print tallest bar height

More Matplotlib exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz