Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
The webAgg backend reports middle click events as right click events. This is caused by these lines:
matplotlib/lib/matplotlib/backends/backend_webagg_core.py
Lines 263 to 269 inede8e56
# The right mouse button pops up a context menu, which | |
# doesn't work very well, so use the middle mouse button | |
# instead. It doesn't seem that it's possible to disable | |
# the context menu in recent versions of Chrome. If this | |
# is resolved, please also adjust the docstring in MouseEvent. | |
ifbutton==2: | |
button=3 |
I don't think I entirely understand the issue described by that comment but I'd argue that it is better to allow users to make the choice to listen for middle clicks rather than to report middle click as right click. Also there does not seem be anything in MouseEvent docstring about this:https://matplotlib.org/3.3.0/api/backend_bases_api.html#matplotlib.backend_bases.MouseEvent
I ran into this when using the ipympl backend (xrefmatplotlib/ipympl#254)
Code for reproduction
In the notebook:
importipywidgetsaswidgetimportmatplotlib.pyplotasplt%matplotlibwidgetout=widgets.Output()@out.capture()defcallback(event):print(event.button)plt.ioff();fig,ax=plt.subplots();plt.ion()fig.canvas.mpl_connect('button_press_event',callback)fs=15ax.text(0.1,0.1,'left click here',fontsize=fs)ax.text(0.5,0.5,'middle click here',fontsize=fs)ax.text(0.7,0.8,'right click here',fontsize=fs)widgets.HBox([out,fig.canvas])
Actual outcome
Expected outcome
in ipython it gives this
Matplotlib version
- Operating system: Ubuntu 20.04
- Matplotlib version: 3.30
- Matplotlib backend (
print(matplotlib.get_backend())
): 'module://ipympl.backend_nbagg' - Python version: 3.8.5
- Jupyter version (if applicable): jupyterlab 2.2.0