0
0
Matplotlibdata~10 mins

DPI settings for resolution 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 set the DPI of the figure to 100.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(dpi=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A100
B200
C50
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using dpi values too low or too high without reason.
Confusing dpi with figure size.
2fill in blank
medium

Complete the code to save the figure with a DPI of 300.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('plot.png', dpi=[1])
Drag options to blanks, or click blank then click option'
A150
B100
C72
D300
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set dpi when saving.
Using dpi values too low for print quality.
3fill in blank
hard

Fix the error in the code to correctly set the DPI when creating a figure.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure([1]=200)
plt.show()
Drag options to blanks, or click blank then click option'
Aresolution
Bdpi
Csize
Dquality
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like resolution or quality.
Confusing dpi with figure size parameters.
4fill in blank
hard

Fill both blanks to create a figure with size 6x4 inches and DPI 150.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=([1], [2]), dpi=150)
plt.show()
Drag options to blanks, or click blank then click option'
A6
B4
C8
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height values.
Using DPI values in figsize instead of inches.
5fill in blank
hard

Fill all three blanks to save a figure with a 5x3 inch size, DPI 200, and filename 'high_res.png'.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=([1], [2]), dpi=[3])
plt.savefig('high_res.png')
Drag options to blanks, or click blank then click option'
A5
B3
C200
D150
Attempts:
3 left
💡 Hint
Common Mistakes
Not matching figsize and dpi values correctly.
Forgetting to set dpi when saving the figure.