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' causes import errors.
Trying to import 'figure' directly is incorrect.
✗ Incorrect
The pyplot module is the main interface for plotting in Matplotlib.
2fill in blank
mediumComplete the code to create a new figure object.
Matplotlib
fig = plt.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot()' creates a plot but not a figure object.
Using 'show()' displays the plot but does not create a figure.
✗ Incorrect
The figure() function creates a new figure object in Matplotlib.
3fill in blank
hardFix the error in the code to add a subplot to the figure.
Matplotlib
ax = fig.[1](111)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subplot' directly on figure causes attribute errors.
Using 'subplots' returns multiple axes, not a single subplot.
✗ Incorrect
The correct method to add a subplot to a figure is add_subplot().
4fill in blank
hardFill both blanks to plot data and display the figure.
Matplotlib
ax.[1]([1, 2, 3], [4, 5, 6]) plt.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' instead of 'plot' changes the plot type.
Using 'draw' instead of 'show' does not display the window.
✗ Incorrect
Use plot() to draw the line plot and show() to display the figure.
5fill in blank
hardFill all three blanks to create a figure, add a subplot, and plot data.
Matplotlib
fig = plt.[1]() ax = fig.[2](111) ax.[3]([10, 20, 30], [1, 4, 9])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'add_subplot' and 'subplots'.
Forgetting to call 'plot()' on the axes object.
✗ Incorrect
Create a figure with figure(), add a subplot with add_subplot(), and plot data with plot().