Bird
0
0

What is wrong with this interactive plot code?

medium📝 Debug Q7 of 15
Matplotlib - Interactive Features
What is wrong with this interactive plot code?
import matplotlib.pyplot as plt
plt.ion()
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])
plt.show()
ax.set_title('My Plot')
Aplt.ion() disables plot display
Bfig, ax = plt.subplots() is invalid syntax
Cax.plot() must be called after plt.show()
DThe title is set after plt.show(), so it won't appear
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.show() effect

    plt.show() displays the plot and blocks further changes in non-interactive mode.
  2. Step 2: Analyze timing of set_title call

    Setting title after plt.show() means the title change may not update on the displayed plot.
  3. Final Answer:

    The title is set after plt.show(), so it won't appear -> Option D
  4. Quick Check:

    Plot update timing = Set title before plt.show() [OK]
Quick Trick: Set plot titles before plt.show() to ensure visibility [OK]
Common Mistakes:
  • Thinking plt.ion() disables display
  • Calling plot after plt.show()
  • Believing plt.subplots() syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes