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.pyplot as plt
for i in range(3):
    plt.figure()
    plt.plot([1,2,3], [4,5,6])
plt.gcf()
AReturns the last created figure object
BReturns None
CRaises an error because figures are not closed
DReturns a list of all figures
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.gcf() behavior

    plt.gcf() returns the current active figure, which is the last created figure.
  2. Step 2: Analyze loop effect

    The loop creates 3 figures, so plt.gcf() returns the third figure object.
  3. Final Answer:

    Returns the last created figure object -> Option A
  4. Quick Check:

    plt.gcf() = last figure [OK]
Quick Trick: plt.gcf() gets current figure, usually last created [OK]
Common Mistakes:
  • Thinking it returns all figures
  • Expecting None
  • Assuming error if figures not closed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes