Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib library.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like numpy or pandas.
Forgetting to import pyplot specifically.
✗ Incorrect
We import matplotlib.pyplot as plt to create plots.
2fill in blank
mediumComplete the code to create a list of categories for the x-axis.
Matplotlib
categories = ['A', 'B', 'C', [1]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string for category.
Adding a list inside the list.
✗ Incorrect
Categories should be strings representing groups, so 'D' is correct.
3fill in blank
hardFix the error in the code to set the width of each bar.
Matplotlib
bar_width = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number.
Using a width larger than 1 causing bars to overlap.
✗ Incorrect
The bar width should be a float less than 1 to avoid overlap.
4fill in blank
hardFill both blanks to correctly calculate the x positions for the second group of bars.
Matplotlib
x2 = [x + [1] for x in x1] plt.bar(x2, group2, width=[2], label='Group 2')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a smaller shift causing bars to overlap.
Using different widths causing uneven bars.
✗ Incorrect
We shift the second group's bars by bar_width to place them side by side and use the same width.
5fill in blank
hardFill all three blanks to create a grouped bar chart with labels and legend.
Matplotlib
plt.bar(x1, [1], width=[2], label='Group 1') plt.bar(x2, [3], width=bar_width, label='Group 2') plt.legend()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up data variables for groups.
Forgetting to add legend for clarity.
✗ Incorrect
We plot group1 and group2 data with the same bar_width and add a legend to distinguish groups.