Repository navigation
Error raised on mouse cursor hover with matplotlib>=3.10 #594
Copy link
Copy link
Open
Description
Describe the issue
Using matplotlib>=3.10.*, making any plot with ipympl raises an error when hovering the mouse over the axes.
Example:
import matplotlib.pyplot as plt
%matplotlib widget
fig, ax = plt.subplots()Hovering the mouse over the plot raises
KeyError Traceback (most recent call last)
File [~/miniforge3/lib/python3.12/site-packages/ipympl/backend_nbagg.py:278](http://localhost:8888/home/nvaytet/miniforge3/lib/python3.12/site-packages/ipympl/backend_nbagg.py#line=277), in Canvas._handle_message(self, object, content, buffers)
275 self.manager.handle_json(content)
277 else:
--> 278 self.manager.handle_json(content)
File [~/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py:474](http://localhost:8888/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py#line=473), in FigureManagerWebAgg.handle_json(self, content)
473 def handle_json(self, content):
--> 474 self.canvas.handle_event(content)
File [~/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py:264](http://localhost:8888/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py#line=263), in FigureCanvasWebAggCore.handle_event(self, event)
261 e_type = event['type']
262 handler = getattr(self, f'handle_{e_type}',
263 self.handle_unknown_event)
--> 264 return handler(event)
File [~/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py:295](http://localhost:8888/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/backends/backend_webagg_core.py#line=294), in FigureCanvasWebAggCore._handle_mouse(self, event)
286 e_type = event['type']
287 button = event['button'] + 1 # JS numbers off by 1 compared to mpl.
288 buttons = { # JS ordering different compared to mpl.
289 button for button, mask in [
290 (MouseButton.LEFT, 1),
291 (MouseButton.RIGHT, 2),
292 (MouseButton.MIDDLE, 4),
293 (MouseButton.BACK, 8),
294 (MouseButton.FORWARD, 16),
--> 295 ] if event['buttons'] & mask # State *after* press[/release.](http://localhost:8888/release.)
296 }
297 modifiers = event['modifiers']
298 guiEvent = event.get('guiEvent')
KeyError: 'buttons'
Note: need to set level to 'Debug' in log console to see it.
The figure is basically inactive.
Could be related to #592 but I did install 0.9.7 and it did not fix the issue.
Downgrading to matplotlib=3.9.4 fixes the issue.
Versions
3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 16:05:46) [GCC 13.3.0]
ipympl version: 0.9.7
Selected Jupyter core packages...
IPython : 8.30.0
ipykernel : 6.29.5
ipywidgets : 8.1.5
jupyter_client : 8.6.3
jupyter_core : 5.7.2
jupyter_server : 2.14.2
jupyterlab : 4.3.1
nbclient : 0.10.1
nbconvert : 7.16.4
nbformat : 5.10.4
notebook : not installed
qtconsole : not installed
traitlets : 5.14.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
ianthomas23 commentedon Apr 29, 2025
The symptoms are indeed the same as #592, and this has been fixed. I cannot reproduce with the same packages in a new environment:
It looks you aren't actually using
ipympl 0.9.7at runtime, even though that version is installed.One report of this issue at matplotlib/matplotlib#29654 was that it was a caching issue which was solved by restarting the kernel a number of times. Please can you try that?
T-Wainwright commentedon May 1, 2025
Getting the same issue with matplotlib 3.10.1, and ipympl 0.9.7, also setting the following behind the scenes to handle interactive figures:
tried restarting a number of times, and reinstalling ipympl with --no-cache-dir, but no luck there.
No interactive features of interactive plots work with the error. Fixed again by downgrading matplotlib to 3.9.4 for now
nvaytet commentedon May 1, 2025
Doing
in the same notebook does yield
0.9.7... 🤔nvaytet commentedon May 2, 2025
Can it be the Python version that is different? I can't think of anything else...
nvaytet commentedon Jun 2, 2025
I have now tried this on a different system and I am still getting the same issue:
ipympl==0.9.7continues to raise the error about buttons withmatplotlib==3.10.3.HojinCho commentedon Jun 2, 2025
Reporting the same issue. Python 3.12.6, matplotlib 3.10.1, and ipympl 0.9.7 from conda-forge, linux; x86-64. Downgrading matplotlib and matplotlib-base to 3.9.4 without changing other packages did resolve the issue.
Older environment with Python 3.12.8, matplotlib 3.9.3, and ipympl 0.9.4 do not experience this issue.
ianhi commentedon Jun 6, 2025
@nvaytet what OS were you on? And did you also install via conda?
@HojinCho can you please try a debugging step for me by installing with pip instead of conda
ianhi commentedon Jun 6, 2025
I tried to replicate your envinronment with conda on macos and was unable to replicate
HojinCho commentedon Jun 6, 2025
Can confirm, matplotlib 3.10.1 and ipympl 0.9.7 installed from pip, under Python 3.12.6 from conda-forge, works without the error (linux x86-64). Seems like the conda-forge distribution has a bug.
Increment build to force rebuild
ianhi commentedon Jun 6, 2025
Thank you @HojinCho! I another debugging request. Could you try installing directly from the
tar.gzon pypi (which is how the conda forge build does it).and let me know if that works?
I want to determine if its an issue with the uploaded source, or with the actual build process
HojinCho commentedon Jun 6, 2025
I did following. From the same environment I tested previously, I ran
pip uninstall ipympl, which removed (obscured the system path with${ENV}just to be safe)and then I ran the command you posted. It produced following output regarding
Node.jsandnpm.I've never seen this output, so I did not try any further and post it here. Should I try to install additional dependencies and proceed?
HojinCho commentedon Jun 6, 2025
Additionally, I tested with another clean environment, with Python 3.12.6 from conda-forge and matplotlib 3.10.1 from PyPI. Running
produced the same error with Node.js and npm.
nvaytet commentedon Jun 6, 2025
I'm running kubuntu 24.04 and installed everything via conda forge
ianhi commentedon Jun 9, 2025
Ok! Thank you both for the info. I think it seems that the conda forge build is broken (at least for Linux) I can't test that easily while traveling. But I'll leave myself a reminder to check this on my linux computer when I'm home in a few weeks. In the meantime it seems installing from pip is a workaround, and hopefully anyone with the power to regenerate a conda build (@martinRenou ?) might be able to fix this
ameraner commentedon Sep 19, 2025
I could reproduce this with matplotlib=3.10.6
ianhi commentedon Sep 19, 2025
I did not check :( and while I am once again travelling. this time I do have my linux laptop.
@ameraner is the issue only with conda for you?
ameraner commentedon Sep 19, 2025
yes, pure conda
ianthomas23 commentedon Sep 22, 2025
This was confirmed to be a problem with VSCode in matplotlib/matplotlib#29654 and matplotlib/matplotlib#30337.
ameraner commentedon Sep 29, 2025
I encountered the issue while using Jupyterlab though...
ej159 commentedon Sep 30, 2025
I encountered the same issue. Downgrading to matplotlib==3.9.6 worked.
nvaytet commentedon Nov 3, 2025
Hi there, is there any news on this? Thanks 🙂
nvaytet commentedon Jan 5, 2026
I tried with
matplotlib==3.10.8andipympl==0.9.8and the error is still there.nvaytet commentedon Jan 15, 2026
Very strange: on a new computer, with
I no longer have the error... 🤔
ianhi commentedon Jan 15, 2026
I am planning on publishing a new release after merging #615 so hopefully that will resolve it for everyone else as well :) and prevent the new computer from catching it as well.
nvaytet commentedon Jun 9, 2026
Any news here? Thanks 🙏