ipympl icon indicating copy to clipboard operation
ipympl copied to clipboard

MPL Event Handling Doc Example not fully functioning

Open jdtsmith opened this issue 4 years ago • 5 comments

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.

image

jdtsmith avatar Mar 31 '21 18:03 jdtsmith

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

ianhi avatar Mar 31 '21 19:03 ianhi

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.

image

jdtsmith avatar Mar 31 '21 20:03 jdtsmith

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:

image

jdtsmith avatar Mar 31 '21 21:03 jdtsmith

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!

ianhi avatar Apr 01 '21 02:04 ianhi

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?

nvaytet avatar Jul 05 '22 18:07 nvaytet