Bird
0
0

What will the following code do?

medium📝 Predict Output Q13 of 15
Matplotlib - Performance and Large Data
What will the following code do?
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('plot.png')
plt.show()
ASave the plot as 'plot.png' and show it in a window.
BDo nothing because Agg disables plotting.
CSave the plot as 'plot.png' but not show any window.
DRaise an error because plt.show() is not supported with Agg.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Agg backend behavior

    Agg backend renders plots to files without opening GUI windows.
  2. Step 2: Analyze plt.show() effect

    With Agg, plt.show() does nothing visible; no window appears.
  3. Final Answer:

    Save the plot as 'plot.png' but not show any window. -> Option C
  4. Quick Check:

    Agg saves file, no window shown [OK]
Quick Trick: Agg saves files silently; plt.show() shows nothing [OK]
Common Mistakes:
  • Expecting a plot window to open
  • Thinking plt.show() causes error
  • Assuming Agg disables saving

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes