-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Bug summary
In jupyter lab, the code snippet below sets the title of the axis to the x,y coords of a mouse click, however in matplotlib 3.5.2 specifically, the clicks aren't registered unless I'm clicking around using the pan or zoom controls of the interactive widget. Downgrading to matplotlib 3.5.1, the clicks are registered with just the cursor as expected with the same ipympl version 0.9.1.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
%matplotlib widget
fig, ax = plt.subplots(figsize=(5,5))
plt.plot(np.random.randint(0, 5, 5))
plt.show()
def onclick(event):
ax.set_title(f'x={event.x}, y={event.y}')
print(f'x={event.x}, y={event.y}')
fig.canvas.mpl_connect('button_press_event', onclick)Actual outcome
No axis title after clicking inside the plot with just a regular cursor

Axis title set after clicking inside the plot with the pan tool of the interactive widget (same if using the zoom tool)

Expected outcome
This screenshot was taken with mpl version 3.5.1 where the regular cursor click was registered and the axis title was changed

Additional information
It's also interesting that under mpl 3.5.2, the cursor remains as the finger cursor icon after clicking while in mpl 3.5.1, the cursor icon changes back to the regular pointer - I'm not sure what that means but it is a difference in behavior...
Some relevant package versions:
matplotlib 3.5.2
ipympl 0.9.1
jupyterlab 3.4.3
Operating system
reproduced on both Ubuntu and macOS
Matplotlib Version
3.5.2
Matplotlib Backend
module://ipympl.backend_nbagg
Python version
3.8.13
Jupyter version
3.4.3
Installation
pip