0
0
Matplotlibdata~20 mins

Figure size for publication in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Figure Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of figure size in inches
What will be the output shape of the figure in inches after running this code?
Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(6, 4))
print(fig.get_size_inches())
A[6. 4.]
B[4. 6.]
C[600 400]
D[0.6 0.4]
Attempts:
2 left
💡 Hint
The figsize parameter sets width and height in inches.
data_output
intermediate
1:30remaining
Number of pixels in saved figure
If you save a figure with figsize=(5, 3) and dpi=100, how many pixels wide and tall will the saved image be?
Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(5, 3), dpi=100)
width, height = fig.get_size_inches() * fig.dpi
print(int(width), int(height))
A50 30
B500 300
C5 3
D100 60
Attempts:
2 left
💡 Hint
Pixels = inches * dpi.
visualization
advanced
2:00remaining
Visual difference of figure sizes
Which option shows the correct code to create two side-by-side plots with different figure sizes for publication?
A
fig, axs = plt.subplots(2, 1)
fig.set_size_inches(10, 4)
axs[0].plot([1, 2, 3])
axs[1].plot([3, 2, 1])
B
fig1 = plt.figure(figsize=(5, 4))
fig2 = plt.figure(figsize=(10, 8))
plt.plot([1, 2, 3])
C
plt.figure(figsize=(10, 4))
plt.subplot(121)
plt.plot([1, 2, 3])
plt.figure(figsize=(5, 4))
plt.subplot(122)
plt.plot([3, 2, 1])
D
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
axs[0].plot([1, 2, 3])
axs[1].plot([3, 2, 1])
Attempts:
2 left
💡 Hint
Use one figure with subplots and set figsize once.
🧠 Conceptual
advanced
1:30remaining
Effect of DPI on figure size and quality
How does increasing the dpi parameter affect the saved figure when figsize is fixed?
AThe saved image has higher pixel dimensions and better quality but same physical size in inches.
BThe saved image has larger physical size in inches but same pixel dimensions.
CThe saved image has lower pixel dimensions and worse quality.
DThe saved image size and quality do not change with dpi.
Attempts:
2 left
💡 Hint
Think about pixels per inch.
🔧 Debug
expert
2:00remaining
Why does this saved figure have unexpected size?
Given this code, why is the saved figure smaller than expected? import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 6)) plt.plot([1, 2, 3]) fig.savefig('plot.png', dpi=50) Options:
Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8, 6))
plt.plot([1, 2, 3])
fig.savefig('plot.png', dpi=50)
AThe plot command resets the figure size to default.
BThe figsize is ignored when dpi is set in savefig.
CThe dpi in savefig is lower than default, reducing pixel dimensions and making the image smaller.
DThe file format PNG does not support large figure sizes.
Attempts:
2 left
💡 Hint
Check how dpi affects saved image size.