Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib plotting library.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole matplotlib instead of pyplot
Using seaborn or pandas instead of matplotlib.pyplot
Forgetting the 'as plt' alias
✗ Incorrect
We import matplotlib.pyplot as plt to create plots.
2fill in blank
mediumComplete the code to create a bar chart for categories and their counts.
Matplotlib
categories = ['A', 'B', 'C'] counts = [10, 15, 7] plt.[1](categories, counts) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot or scatter which are better for continuous data
Using hist which is for numerical distributions
✗ Incorrect
The bar function creates bar charts, which are good for categorical data.
3fill in blank
hardFix the error in the code to label the x-axis with category names.
Matplotlib
plt.bar([1, 2, 3], [5, 7, 3]) plt.xticks([1, 2, 3], [1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using counts or positions as labels instead of category names
Passing numbers instead of strings for labels
✗ Incorrect
The xticks function sets the labels on the x-axis. We want to label the bars with category names.
4fill in blank
hardFill both blanks to create a horizontal bar chart with labels and title.
Matplotlib
plt.[1](counts, categories) plt.xlabel('[2]') plt.title('Category Counts') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bar instead of barh for horizontal bars
Labeling the x-axis as 'Categories' instead of 'Counts'
✗ Incorrect
barh creates horizontal bars. The x-axis label should describe the counts.
5fill in blank
hardFill all three blanks to create a pie chart with labels and percentage display.
Matplotlib
plt.[1](counts, labels=[2], autopct='[3]') plt.title('Category Distribution') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bar instead of pie for pie charts
Not passing labels or passing wrong labels
Incorrect format string for autopct
✗ Incorrect
The pie function creates pie charts. Labels are category names. autopct formats percentages.