Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib plotting library.
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' causes import errors.
Trying to import 'charts' or 'graph' which do not exist.
✗ Incorrect
We import matplotlib.pyplot as plt to create plots 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' or 'line' which are not matplotlib functions.
Trying to use 'graph' which is not a valid method.
✗ Incorrect
The plot function draws line plots in matplotlib.
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 a method for axes objects, not pyplot.
Trying 'add_title' or 'plot_title' which do not exist.
✗ Incorrect
The correct function to add a title is plt.title().
4fill in blank
hardFill both blanks to customize the x-axis and y-axis labels.
Matplotlib
plt.plot([1, 2, 3], [4, 5, 6]) plt.xlabel([1]) plt.[2]('Value') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel twice or plt.ylabel as a string.
Confusing the label names or functions.
✗ Incorrect
Use plt.xlabel('Time') and plt.ylabel('Value') to label axes.
5fill in blank
hardFill all three blanks to create a customized scatter plot with color and size.
Matplotlib
plt.scatter([1, 2, 3], [4, 5, 6], c=[1], s=[2], marker=[3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid marker symbols or wrong data types for size.
Confusing color strings or missing quotes.
✗ Incorrect
Use c='blue' for color, s=100 for size, and marker='o' for circle markers.