Recall & Review
beginner
What function is used in Python's matplotlib to save a figure to a file?
The function
savefig() is used to save the current figure to a file in matplotlib.Click to reveal answer
beginner
Which file formats can you save a matplotlib figure as?
You can save figures in formats like PNG, JPG, PDF, SVG, and EPS by specifying the file extension in
savefig().Click to reveal answer
intermediate
How do you save a figure with a transparent background in matplotlib?
Use
plt.savefig('filename.png', transparent=True) to save the figure with a transparent background.Click to reveal answer
intermediate
Why might you want to call
plt.close() after saving a figure?Calling
plt.close() frees up memory by closing the figure, especially useful when saving many figures in a loop.Click to reveal answer
beginner
What does the
dpi parameter control in savefig()?The
dpi parameter controls the resolution (dots per inch) of the saved image, affecting its quality and file size.Click to reveal answer
Which command saves the current matplotlib figure as a PNG file named 'plot.png'?
✗ Incorrect
The correct function to save a figure is
savefig(), and the filename must include the extension.What happens if you save a figure without specifying the file extension?
✗ Incorrect
Matplotlib saves it as a PNG by default if no file extension is provided.
How can you save a figure with higher resolution?
✗ Incorrect
Increasing the
dpi value in savefig() increases the image resolution.Which of these is NOT a valid file format for saving matplotlib figures?
✗ Incorrect
DOCX is a document format, not an image format supported by matplotlib.
Why is it good practice to call
plt.close() after saving a figure in a loop?✗ Incorrect
Closing the figure frees memory and prevents too many open figures when saving multiple plots.
Explain how to save a matplotlib figure as a high-quality PNG file with a transparent background.
Think about the parameters you pass to savefig.
You got /4 concepts.
Describe why managing figures with plt.close() is important when saving many plots in a script.
Consider what happens if you don't close figures.
You got /4 concepts.