0
0
Matplotlibdata~10 mins

Why bar charts compare categories in Matplotlib - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a bar chart showing sales for each fruit category.

Matplotlib
import matplotlib.pyplot as plt
categories = ['Apples', 'Bananas', 'Cherries']
sales = [10, 15, 7]
plt.bar([1], sales)
plt.show()
Drag options to blanks, or click blank then click option'
Acategories
Bsales
Crange(len(sales))
D'Apples'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sales instead of categories for x-axis
Using a single string instead of a list for x-axis
2fill in blank
medium

Complete the code to add labels to the x-axis showing category names.

Matplotlib
plt.bar(categories, sales)
plt.xlabel([1])
plt.show()
Drag options to blanks, or click blank then click option'
A'Fruit Type'
Bsales
Ccategories
D'Sales'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the data list instead of a label string
Leaving the label blank
3fill in blank
hard

Fix the error in the code to correctly display the bar chart comparing categories.

Matplotlib
plt.bar(categories, [1])
plt.xticks(rotation=45)
plt.show()
Drag options to blanks, or click blank then click option'
A['10', '15', '7']
Bcategories
Csales
Drange(len(categories))
Attempts:
3 left
💡 Hint
Common Mistakes
Using categories instead of sales for bar heights
Using string versions of numbers instead of integers
4fill in blank
hard

Fill both blanks to create a bar chart with category names and sales, and add a title.

Matplotlib
plt.bar([1], [2])
plt.title('Sales by [3]')
plt.show()
Drag options to blanks, or click blank then click option'
Acategories
Bsales
CFruit Type
DApples
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping categories and sales
Using a category name instead of a descriptive title
5fill in blank
hard

Fill all three blanks to create a bar chart comparing categories with labels and rotated x-axis labels.

Matplotlib
plt.bar([1], [2])
plt.xlabel('[3]')
plt.xticks(rotation=90)
plt.show()
Drag options to blanks, or click blank then click option'
Acategories
Bsales
CFruit Type
DSales
Attempts:
3 left
💡 Hint
Common Mistakes
Labeling x-axis as 'Sales' instead of 'Fruit Type'
Swapping categories and sales in the bar function