ipympl
ipympl copied to clipboard
MPL Event Handling Doc Example not fully functioning
I tried the example from the MPL event handling docs: a bar chart with draggable bars ("extra credit" version). This works fine in QT5Agg backend, but doesn't fully work in Jupyter Lab (v3.0.7) with ipympl (v0.7.0). The plot displays fine, and I can see that click and drag events are being received by the widget, but during drag, the bars vanish. In fact, if in the click handler I include a color change:
self.rect.set(animated=True,color='red')
Then I can see a faint red outline after the bar is "dropped" in the correct location (see below). So clearly the click/drag/release events are working, but the bar drawing during and after drag via draw_artist and blit are not.

Hi what version of matplotlib are you using for this? ipympl doesn't have any blit support until at least matplotlib 3.4 - though there were some issues with it so the backend will still have supports_blit=False but the methods do exist and hopefully should mostly work: https://github.com/matplotlib/matplotlib/pull/19762
I was on 3.3.3. Just upgraded to 3.4.1 and there is improvement, but blitting leaves a "boundary" around each bar as it moves. If I comment out the blit during move, it's invisible while moving but shows up correction on being dropped. So it's clearly the blit of the bar artist leaving behind some artifacts.

Another bit of debugging. If I artificially limit movements to be relatively quite large (dropping all motion events that are "too small"), and move slowly it works just fine:

I think what you're running into now is this issue from core matplotlib: https://github.com/matplotlib/matplotlib/issues/19116
Unfortunately no one has figured out a solution yet, your thoughts are of course welcome!
You get the same effect in the looking glass example from the docs.
Since the performance is so much better in the Qt backend, is there any way to embed the Qt window inside the jupyter notebook? (using an ipywidget or something?). I guess if that was possible, then the ipympl project wouldn't really exist?