Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dpi values too low or too high without reason.
Confusing dpi with figure size.
✗ Incorrect
The dpi parameter controls the dots per inch (resolution) of the figure. Setting dpi=100 sets the resolution to 100 dots per inch.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set dpi when saving.
Using dpi values too low for print quality.
✗ Incorrect
When saving a figure, dpi controls the resolution of the saved image. 300 dpi is a common high-quality print resolution.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like resolution or quality.
Confusing dpi with figure size parameters.
✗ Incorrect
The correct parameter name to set resolution is dpi, not resolution or size.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height values.
Using DPI values in figsize instead of inches.
✗ Incorrect
figsize takes a tuple of (width, height) in inches. Here, width=6 and height=4 inches.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not matching figsize and dpi values correctly.
Forgetting to set dpi when saving the figure.
✗ Incorrect
Set figsize to (5, 3) inches and dpi to 200 for high resolution. Filename is already given.