Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
Matplotlib - Performance and Large Data
What is wrong with this code snippet?
import matplotlib
matplotlib.use('Agg')
plt.plot([1, 2, 3])
plt.savefig('plot.png')
Aplt is not imported before use
Bmatplotlib.use('Agg') must be called after plt import
CAgg backend does not support savefig
DNo error; code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check imports

    plt (matplotlib.pyplot) is used but not imported.
  2. Step 2: Confirm backend usage

    Backend is set correctly before pyplot import, but pyplot import is missing.
  3. Final Answer:

    plt is not imported before use -> Option A
  4. Quick Check:

    Always import pyplot as plt before use [OK]
Quick Trick: Import pyplot as plt before using it [OK]
Common Mistakes:
  • Forgetting to import pyplot
  • Misplacing backend setting
  • Assuming Agg disables savefig

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes