Bird
0
0

You wrote this code but get an error:

medium📝 Debug Q14 of 15
Matplotlib - Interactive Features
You wrote this code but get an error:
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')
plt.plot([1, 2], [3, 4])
plt.show()

What is the likely cause?
ABackend must be set before importing pyplot
BThe 'TkAgg' backend is not installed
Cplt.plot() syntax is incorrect
Dplt.show() cannot be used with 'TkAgg'
Step-by-Step Solution
Solution:
  1. Step 1: Check backend setting order

    The backend must be set before importing pyplot to avoid errors.
  2. Step 2: Analyze the code order

    Here, pyplot is imported before setting backend, causing the error.
  3. Final Answer:

    Backend must be set before importing pyplot -> Option A
  4. Quick Check:

    Set backend before pyplot import = A [OK]
Quick Trick: Set backend before importing pyplot to avoid errors [OK]
Common Mistakes:
  • Setting backend after importing pyplot
  • Assuming backend installation error
  • Blaming plot syntax or plt.show()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes