Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the pyplot module from matplotlib.
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'.
Trying to import 'charts' which does not exist.
✗ Incorrect
We import the pyplot module as plt to use its plotting functions easily.
2fill in blank
mediumComplete the code to create a simple line plot of y values.
Matplotlib
plt.[1]([1, 2, 3, 4], [10, 20, 25, 30]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'draw' which is not a pyplot function.
Using 'line' which does not exist in pyplot.
✗ Incorrect
The plot function draws a line plot connecting the points.
3fill in blank
hardFix the error in the code to add a title to the plot.
Matplotlib
plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]('My Plot') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set_title' which is for axes, not pyplot interface.
Using 'add_title' or 'plot_title' which do not exist.
✗ Incorrect
The title function sets the title of the current plot.
4fill in blank
hardFill both blanks to label the x-axis and y-axis of the plot.
Matplotlib
plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]('Time') plt.[2]('Speed') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'title' instead of axis labels.
Using 'legend' which is for plot legends.
✗ Incorrect
xlabel and ylabel set the labels for the x and y axes respectively.
5fill in blank
hardFill all three blanks to create a scatter plot with red dots and show it.
Matplotlib
plt.[1]([5, 7, 8], [2, 3, 5], c=[2], marker=[3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'scatter' for scatter plots.
Forgetting quotes around color and marker.
✗ Incorrect
The scatter function creates scatter plots. The color 'red' and marker 'o' specify red dots.