Bird
0
0

What will be the background color of the saved image after running this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Export and Publication Quality
What will be the background color of the saved image after running this code?
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig('test.png', transparent=True)
ABlue background
BWhite background
CBlack background
DTransparent (no background color)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the savefig parameters

    The code uses transparent=True in plt.savefig(), which makes the saved image background transparent.
  2. Step 2: Understand default background without transparency

    Without transparent=True, the background would be white by default, but here it is overridden.
  3. Final Answer:

    The saved image background will be transparent (no background color). -> Option D
  4. Quick Check:

    transparent=True means transparent background [OK]
Quick Trick: transparent=True removes background color in saved images [OK]
Common Mistakes:
  • Assuming default white background remains
  • Thinking plot line color affects background
  • Confusing transparency with figure facecolor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes