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 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 horizontal bar chart using matplotlib.
Matplotlib
plt.barh([1], values, color=colors) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing values instead of categories as the first argument.
Using
bar instead of barh for horizontal bars.✗ Incorrect
The barh function needs the categories on the y-axis.
3fill in blank
hardFix the error in the code to center the bars around zero for diverging values.
Matplotlib
plt.barh(categories, [1], color=colors) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using raw values without centering.
Subtracting a fixed number instead of the mean.
✗ Incorrect
Subtracting the mean centers the bars around zero for diverging charts.
4fill in blank
hardFill both blanks to create a color list that colors positive values green and negative values red.
Matplotlib
colors = ['green' if val [1] 0 else 'red' for val in [2]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using categories instead of values for color assignment.
✗ Incorrect
We check if each value is greater than zero to assign green, else red.
5fill in blank
hardFill all three blanks to add labels and a title to the diverging bar chart.
Matplotlib
plt.xlabel('[1]') plt.ylabel('[2]') plt.title('[3]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x and y axis labels.
Using unclear or missing titles.
✗ Incorrect
Labels describe the x-axis as 'Value', y-axis as 'Category', and the chart has a descriptive title.