0
0
Matplotlibdata~10 mins

Saving figures to files 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 save the figure as a PNG file named 'plot.png'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]('plot.png')
Drag options to blanks, or click blank then click option'
Asavefig
Bfigure
Cshow
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.show() instead of plt.savefig()
Trying to save the figure before plotting
Misspelling the function name
2fill in blank
medium

Complete the code to save the figure as a PDF file named 'chart.pdf'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([10, 20, 30], [1, 4, 9])
plt.[1]('chart.pdf')
Drag options to blanks, or click blank then click option'
Ashow
Bsavefig
Cclose
Dfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.show() instead of plt.savefig()
Not specifying the file name with extension
Trying to save before plotting
3fill in blank
hard

Fix the error in the code to save the figure as 'output.jpg'.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.[1]('output.jpg')
Drag options to blanks, or click blank then click option'
Asavefig
Bsave
Csave_figure
Dsave_plot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.save() which does not exist
Misspelling savefig
Not calling the function on plt
4fill in blank
hard

Fill both blanks to save the figure as a high-resolution PNG file named 'highres.png' with 300 dpi.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([5, 10, 15], [2, 4, 6])
plt.[1]('highres.png', [2]=300)
Drag options to blanks, or click blank then click option'
Asavefig
Bdpi
Cquality
Dresolution
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter name like 'quality' or 'resolution'
Not specifying dpi for high resolution
Using plt.show() instead of plt.savefig()
5fill in blank
hard

Fill all three blanks to save the figure as 'custom.svg' with transparent background and tight bounding box.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([7, 8, 9], [1, 3, 5])
plt.[1]('custom.svg', [2]=True, [3]='tight')
Drag options to blanks, or click blank then click option'
Asavefig
Btransparent
Cbbox_inches
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.show() instead of plt.savefig()
Misspelling parameter names
Not using bbox_inches to reduce whitespace