0
0
Matplotlibdata~10 mins

Why export quality matters in Matplotlib - Test Your Understanding

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

Complete the code to create a simple line plot.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.[1]()
Drag options to blanks, or click blank then click option'
Ashow
Bsavefig
Cplot
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using savefig instead of show will save the plot but not display it.
Calling plot again instead of show will add more lines instead of displaying.
2fill in blank
medium

Complete the code to save the plot as a PNG file.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.[1]('plot_image.png')
Drag options to blanks, or click blank then click option'
Ashow
Bplot
Csavefig
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using show instead of savefig will display but not save the plot.
Using close will close the plot without saving.
3fill in blank
hard

Fix the error in saving the plot with high resolution.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.savefig('high_res_plot.png', dpi=[1])
Drag options to blanks, or click blank then click option'
Adpi
B300
C'300'
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Passing dpi as a string causes an error.
Using too low dpi results in poor image quality.
4fill in blank
hard

Fill both blanks to save a plot with a transparent background and tight layout.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.savefig('transparent_plot.png', [1]=True, [2]='tight')
Drag options to blanks, or click blank then click option'
Atransparent
Bdpi
Cbbox_inches
Dfacecolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using facecolor instead of transparent for transparency.
Not using bbox_inches='tight' causes extra whitespace.
5fill in blank
hard

Fill all three blanks to save a plot with a custom size, high dpi, and no axis.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=([1], [2]))
ax.plot([1, 2, 3], [3, 2, 1])
ax.axis([3])
fig.savefig('custom_plot.png', dpi=300)
Drag options to blanks, or click blank then click option'
A8
B6
C'off'
D'on'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for figsize.
Using 'on' instead of 'off' to hide axes.