Bird
0
0

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

medium📝 Predict Output Q13 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], [4, 5, 6])
plt.savefig('myplot.png', transparent=True)
AWhite background
BTransparent background
CBlack background
DRed background
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the plt.savefig() call

    The code uses transparent=True in plt.savefig(), which sets the saved image background to transparent.
  2. Step 2: Understand default background behavior

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

    Transparent background -> Option B
  4. Quick Check:

    transparent=True means transparent background [OK]
Quick Trick: transparent=True means no background color [OK]
Common Mistakes:
  • Assuming default white background
  • Confusing plot color with background
  • Thinking transparent=True changes plot line color

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes