matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.59k stars 225 forks source link

zoom and move buttons broken for mpl 3.7.0 #516

Closed Linusnie closed 1 year ago

Linusnie commented 1 year ago

After installing jupyterlab and ipympl I'm able to make plots that can be displayed and resized, but the move and zoom buttons don't work. Tooltips are shown if I hover the cursor over the buttons, but clicking them gives no response.

I also posted in https://github.com/matplotlib/ipympl/issues/70 which was closed as outdated

package versions:

ipykernel 6.21.2
ipympl 0.9.2
ipython 8.10.0
ipython-genutils 0.2.0
ipywidgets 8.0.4
jupyter_client 8.0.2
jupyter_core 5.2.0
jupyter-events 0.5.0
jupyter_server 2.2.1
jupyter_server_fileid 0.6.0
jupyter_server_terminals 0.4.4
jupyter_server_ydoc 0.6.1
jupyter-ydoc 0.2.2
jupyterlab 3.6.1
jupyterlab-darkside-ui 0.2.3
jupyterlab-pygments 0.2.2
jupyterlab_server 2.19.0
jupyterlab-widgets 3.0.5

jupyter labextension list returns the following:

jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
jupyter-matplotlib v0.11.2 enabled OK
@jupyter-widgets/jupyterlab-manager v5.0.5 enabled OK (python, jupyterlab_widgets)
@dunovank/jupyterlab_darkside_ui v0.2.3 enabled OK (python, jupyterlab_darkside_ui)

Screenshot from 2023-02-14 23-40-58

ianhi commented 1 year ago

@Linusnie are you using ipympl in vscode or in jupyterlab?

Linusnie commented 1 year ago

@Linusnie are you using ipympl in vscode or in jupyterlab?

I'm using jupyterlab

ianhi commented 1 year ago

Ok great. Two follow up questions:

  1. Can you post a gif of you trying to use them?
  2. Can you post the contents of the browser console after trying this here (see how to access https://balsamiq.com/support/faqs/browserconsole/)
Linusnie commented 1 year ago

sure! There's quite a bit of output in the console, most relevant might be this one: Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason: Control comm was closed too early? (last image)

screencast Screenshot from 2023-02-15 10-08-14 Screenshot from 2023-02-15 10-09-08 Screenshot from 2023-02-15 10-09-23

Linusnie commented 1 year ago

in case it's relevant, things like ipywidgets.IntSlider(10) works and I can interact with no issue

Linusnie commented 1 year ago

Update: looks like the problem is caused by an incompatibility with matplotlib. If I try the same notebook in vs code it prints out the following error message when I try to use the plot (not sure why it doesn't show up when using jupyterlab).

KeyError                                  Traceback (most recent call last)
File ~/workspace/convex_relaxations/venv3.10/lib/python3.10/site-packages/ipympl/backend_nbagg.py:279, in Canvas._handle_message(self, object, content, buffers)
    276     self.manager.handle_json(content)
    278 else:
--> 279     self.manager.handle_json(content)

File ~/workspace/convex_relaxations/venv3.10/lib/python3.10/site-packages/matplotlib/backends/backend_webagg_core.py:462, in FigureManagerWebAgg.handle_json(self, content)
    461 def handle_json(self, content):
--> 462     self.canvas.handle_event(content)

File ~/workspace/convex_relaxations/venv3.10/lib/python3.10/site-packages/matplotlib/backends/backend_webagg_core.py:266, in FigureCanvasWebAggCore.handle_event(self, event)
    263 e_type = event['type']
    264 handler = getattr(self, 'handle_{0}'.format(e_type),
    265                   self.handle_unknown_event)
--> 266 return handler(event)

File ~/workspace/convex_relaxations/venv3.10/lib/python3.10/site-packages/matplotlib/backends/backend_webagg_core.py:293, in FigureCanvasWebAggCore._handle_mouse(self, event)
    290 button = event['button'] + 1
    292 e_type = event['type']
--> 293 modifiers = event['modifiers']
    294 guiEvent = event.get('guiEvent')
    295 if e_type in ['button_press', 'button_release']:

KeyError: 'modifiers'

After downgrading matplotlib using python -m pip install matplotlib==3.6.2 zooming and moving works as usual

ianhi commented 1 year ago

Ahh indeed broken for the new matplotlib. Thank you for reporting!

f I try the same notebook in vs code it prints out the following error message when I try to use the plot (not sure why it doesn't show up when using jupyterlab).

You can see the errors by going View> Show Log Console and changing thelevel to info

ianhi commented 1 year ago

I think the breakage is caused by https://github.com/matplotlib/matplotlib/pull/23473 which requires us to add modifiers to events from javascript side, because we don't rely on mpl.js we did pick up the changes from that side, only the python side.

ianhi commented 1 year ago

Thanks again for reporting @Linusnie ! The fix has been merged, trying to remember how to make a release now - once that's done version 0.9.3 and up should work with latest matplotlib

ianhi commented 1 year ago

@Linusnie should be fixed in the now release version 0.9.3

Linusnie commented 1 year ago

@ianhi awesome! thanks for the quick response

Sciroccogti commented 1 year ago

Is it really fixed? ipympl=0.9.3 with matplotlib=3.7.0 still get the same error.