Recall & Review
beginner
What function in matplotlib do you use to save a figure to a file?
You use
plt.savefig() to save the current figure to a file.Click to reveal answer
beginner
How do you save a figure as a PNG file named 'plot.png'?
Use
plt.savefig('plot.png') to save the figure as a PNG file named 'plot.png'.Click to reveal answer
intermediate
What parameter do you use in
savefig() to set the resolution of the saved image?Use the
dpi parameter to set the resolution, for example plt.savefig('plot.png', dpi=300).Click to reveal answer
beginner
True or False: You must call
plt.show() before plt.savefig() to save the figure.False. You should call
plt.savefig() before plt.show() because plt.show() can clear the figure.Click to reveal answer
intermediate
How can you save a figure in vector format using matplotlib?
Save the figure as a PDF or SVG by using the file extension in
savefig(), for example plt.savefig('plot.pdf') or plt.savefig('plot.svg').Click to reveal answer
Which command saves the current matplotlib figure as a JPEG file named 'image.jpg'?
✗ Incorrect
plt.savefig() is the correct function to save figures. The filename extension determines the format.What does the
dpi parameter control in plt.savefig()?✗ Incorrect
dpi sets the resolution, higher dpi means better image quality.If you want to save a figure as a vector graphic, which file extension should you use?
✗ Incorrect
SVG is a vector graphic format. PDF also works for vector graphics.
When should you call
plt.savefig() in your code?✗ Incorrect
Call
plt.savefig() before plt.show() because plt.show() can clear the figure.Which of these is NOT a valid file format for
plt.savefig()?✗ Incorrect
.exe is an executable file, not an image format.Explain how to save a matplotlib figure to a file with high resolution.
Think about the function name and the dpi setting.
You got /4 concepts.
Describe the difference between saving a figure as PNG and SVG in matplotlib.
Consider image quality and scaling.
You got /4 concepts.