Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib plotting module.
Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot'.
Using 'charts' or 'graph' which are not valid matplotlib modules.
✗ Incorrect
The matplotlib.pyplot module is imported as plt to create plots.
2fill in blank
mediumComplete the code to create a list of x values from 0 to 4.
Matplotlib
x = [[1] for i in range(5)]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying or adding to 'i' changes the sequence.
Using 'i-1' results in negative numbers.
✗ Incorrect
Using 'i' directly creates a list [0, 1, 2, 3, 4].
3fill in blank
hardFix the error in the code to fill the area between y1 and y2.
Matplotlib
plt.fill_between(x, y1, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using y3 which may not be defined.
Using x instead of a y array.
Repeating y1 as both y arrays.
✗ Incorrect
The fill_between function needs y2 as the second y-value array to fill between y1 and y2.
4fill in blank
hardFill both blanks to create y1 and y2 lists for the area chart.
Matplotlib
y1 = [i[1]2 for i in x] y2 = [i[2]1 for i in x]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or integer division instead of multiplication or addition.
Mixing up the operators for y1 and y2.
✗ Incorrect
y1 is each x value multiplied by 2, y2 is each x value plus 1.
5fill in blank
hardFill all three blanks to plot the area chart with labels and show it.
Matplotlib
plt.fill_between(x, y1, y2, color='skyblue', alpha=[1]) plt.title('[2]') plt.show() # Display the [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alpha values outside 0-1 range.
Forgetting to call plt.show() to display the chart.
Setting title to something unrelated.
✗ Incorrect
Alpha controls transparency, title sets the chart title, and plt.show() displays the plot.