Bird
0
0

What will be the output behavior of this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Interactive Features
What will be the output behavior of this code?
import matplotlib.pyplot as plt
import mplcursors
fig, ax = plt.subplots()
line, = ax.plot([1, 2, 3], [4, 5, 6], marker='o')
mplcursors.cursor(line)
plt.show()
AHovering over points shows their coordinates as labels
BThe plot shows but no hover labels appear
CThe code raises an error due to missing arguments
DThe plot shows with a static legend instead of hover labels
Step-by-Step Solution
Solution:
  1. Step 1: Understand mplcursors usage on line plot

    Calling mplcursors.cursor(line) enables hover labels on the line's points.
  2. Step 2: Predict interactive behavior

    Hovering over each marker point will display its (x, y) coordinates as a label.
  3. Final Answer:

    Hovering over points shows their coordinates as labels -> Option A
  4. Quick Check:

    Hover labels appear on points = True [OK]
Quick Trick: mplcursors.cursor(line) shows hover labels on line points [OK]
Common Mistakes:
  • Expecting static legend instead of hover labels
  • Thinking code errors without arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes