Challenge - 5 Problems
Transparent Background Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of saving a plot with transparent background
What will be the background color of the saved image when running this code?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('plot.png', transparent=True) plt.close()
Attempts:
2 left
💡 Hint
Check the meaning of the 'transparent' parameter in plt.savefig.
✗ Incorrect
Setting transparent=True in plt.savefig makes the background of the saved image transparent instead of the default white.
❓ data_output
intermediate2:00remaining
Background color of figure and axes with transparency
Given this code, what is the background color of the figure and axes when displayed?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() fig.patch.set_alpha(0.5) ax.plot([1, 2], [3, 4]) plt.show()
Attempts:
2 left
💡 Hint
Alpha controls transparency but default colors remain unless changed.
✗ Incorrect
Setting alpha on figure patch changes figure background transparency but axes background stays white unless changed.
🔧 Debug
advanced2:00remaining
Why does transparent=True not work as expected?
This code saves a plot with transparent=True but the background is still white. What is the likely cause?
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1, 2, 3], [3, 2, 1]) plt.savefig('plot.png', transparent=True) plt.close()
Attempts:
2 left
💡 Hint
Check if figure or axes background colors are set explicitly.
✗ Incorrect
If figure or axes background colors are set explicitly to opaque colors, transparent=True will not make them transparent.
❓ visualization
advanced2:00remaining
Visual effect of transparent background on saved plot
Which option best describes the visual difference between these two saved images: one saved with transparent=True and one without?
Matplotlib
import matplotlib.pyplot as plt plt.plot([0, 1], [0, 1]) plt.savefig('opaque.png') plt.savefig('transparent.png', transparent=True) plt.close()
Attempts:
2 left
💡 Hint
Think about what transparent background means for image files.
✗ Incorrect
Saving with transparent=True removes the background color, so the image background is transparent and shows whatever is behind it.
🧠 Conceptual
expert3:00remaining
Effect of transparent backgrounds on plot elements
When saving a matplotlib plot with transparent=True, which elements remain fully opaque by default?
Attempts:
2 left
💡 Hint
Consider what transparent=True affects in the saved image.
✗ Incorrect
transparent=True affects figure and axes backgrounds but plot lines, markers, and text remain fully visible and opaque unless their alpha is changed.