0
0
Matplotlibdata~10 mins

Figure size and DPI 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 create a figure with size 8 by 6 inches.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A[8, 6]
B(8, 6)
C{8, 6}
D8, 6
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or set instead of a tuple for figsize.
Not using any brackets around the numbers.
2fill in blank
medium

Complete the code to set the DPI (dots per inch) of the figure to 150.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(dpi=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A100
B72
C150
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using a DPI value that is too low or default (like 72).
Confusing DPI with figure size.
3fill in blank
hard

Fix the error in the code to create a figure with size 10 by 4 inches and DPI 120.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1], dpi=120)
plt.show()
Drag options to blanks, or click blank then click option'
A(10, 4)
B[10, 4]
C{10, 4}
D10, 4
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or set instead of a tuple for figsize.
Not using any brackets around the numbers.
4fill in blank
hard

Fill both blanks to create a figure with size 12 by 8 inches and DPI 100.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1], dpi=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A(12, 8)
B100
C150
D[12, 8]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for figsize.
Setting dpi to the wrong number.
5fill in blank
hard

Fill all three blanks to create a figure with size 5 by 5 inches, DPI 200, and save it as 'output.png'.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1], dpi=[2])
fig.savefig([3])
plt.show()
Drag options to blanks, or click blank then click option'
A(5, 5)
B200
C'output.png'
D'figure.png'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the filename.
Using a list instead of a tuple for figsize.
Setting dpi to a wrong value.