0
0
Matplotlibdata~10 mins

Memory management with large figures in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the matplotlib pyplot module correctly.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Acharts
Bpyplot
Cplot
Dfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot'.
Using 'charts' which is not a matplotlib module.
Using 'figure' which is a function, not a module.
2fill in blank
medium

Complete the code to create a new figure with a large size to manage memory better.

Matplotlib
fig = plt.figure(figsize=[1])
Drag options to blanks, or click blank then click option'
A(10, 5)
B(5, 3)
C(20, 15)
D(12, 8)
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing too small figure size like (5, 3).
Choosing too large figure size like (20, 15) which uses more memory.
3fill in blank
hard

Fix the error in the code to properly close a figure and free memory.

Matplotlib
plt.[1](fig)
Drag options to blanks, or click blank then click option'
Aclose
Bclear
Cremove
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' which is not a matplotlib function.
Using 'remove' which does not close figures.
Using 'clear' which clears axes but does not close figures.
4fill in blank
hard

Fill both blanks to create a plot and then clear the current figure to save memory.

Matplotlib
plt.plot(x, y)
plt.[1]()
plt.[2]()
Drag options to blanks, or click blank then click option'
Ashow
Bclose
Cclf
Ddraw
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'close' instead of 'clf' to clear the figure.
Using 'draw' which redraws but does not clear or close.
5fill in blank
hard

Fill all three blanks to create a large figure, plot data, and then close the figure to manage memory.

Matplotlib
fig = plt.figure(figsize=[1])
plt.plot(x, y)
plt.[2]()
plt.[3](fig)
Drag options to blanks, or click blank then click option'
A(15, 10)
Bclose
Cshow
D(8, 6)
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large figure size causing high memory use.
Not closing the figure after plotting.
Calling show after close instead of before.