Bird
0
0

What will be printed when the following code runs and the user clicks on the red circle?

medium📝 Predict Output Q4 of 15
Matplotlib - Interactive Features
What will be printed when the following code runs and the user clicks on the red circle?
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
circle = plt.Circle((0.5, 0.5), 0.1, color='red', picker=True)
ax.add_patch(circle)

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

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()
ANo output printed
BPicked: <matplotlib.patches.Circle object at ...>
CError: 'Circle' object has no attribute 'picker'
DPicked: None
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code setup

    A red circle patch is added with picker=True, enabling pick events on it.
  2. Step 2: Analyze the pick event handler

    The on_pick function prints the picked artist object when the circle is clicked.
  3. Final Answer:

    Picked: <matplotlib.patches.Circle object at ...> -> Option B
  4. Quick Check:

    Pick event prints artist object [OK]
Quick Trick: picker=True enables picking and event prints artist [OK]
Common Mistakes:
  • Expecting None or error instead of artist object
  • Forgetting to set picker=True

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes