Bird
0
0

Identify the error in this code snippet that tries to use pick events:

medium📝 Debug Q6 of 15
Matplotlib - Interactive Features
Identify the error in this code snippet that tries to use pick events:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
line, = ax.plot([1, 2, 3], [4, 5, 6])

def on_pick(event):
    print('Picked:', event.artist)

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()
AThe figure is not created properly
BThe event handler function is missing parameters
CThe event name 'pick_event' is incorrect
DThe plot line does not have picker enabled
Step-by-Step Solution
Solution:
  1. Step 1: Check if the plot line is pickable

    The line is created without setting picker parameter, so it won't respond to pick events.
  2. Step 2: Verify other parts

    The event handler and event name are correct, and figure creation is fine.
  3. Final Answer:

    The plot line does not have picker enabled -> Option D
  4. Quick Check:

    Missing picker disables pick events [OK]
Quick Trick: Always set picker to enable pick events [OK]
Common Mistakes:
  • Forgetting to set picker=True or a tolerance
  • Assuming event handler signature is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes