Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q4 of 15
Matplotlib - Performance and Large Data
What will be the output of this code snippet?
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig('plot.png')
print('Done')
AA plot window opens and 'Done' is printed
BError because Agg backend does not support savefig
C'Done' is printed and 'plot.png' file is saved without opening a window
DNothing happens because Agg disables plotting
Step-by-Step Solution
Solution:
  1. Step 1: Analyze backend behavior

    Agg backend does not open GUI windows but supports saving plots to files.
  2. Step 2: Trace code execution

    The plot is created, saved as 'plot.png', and 'Done' is printed. No window opens.
  3. Final Answer:

    'Done' is printed and 'plot.png' file is saved without opening a window -> Option C
  4. Quick Check:

    Agg saves files, no GUI window [OK]
Quick Trick: Agg backend saves files silently, no GUI [OK]
Common Mistakes:
  • Expecting a plot window to open
  • Thinking Agg disables savefig
  • Assuming code throws error with Agg

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes