FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid event accumulation in webagg backend. by raphaelquast · Pull Request #27160 · matplotlib/matplotlib · GitHub

Repository navigation

Avoid event accumulation in webagg backend. - #27160

Open
raphaelquast wants to merge 8 commits into
matplotlib:mainfrom
raphaelquast:webagg_blit_fix
Open

raphaelquast wants to merge 8 commits into
matplotlib:mainfrom
raphaelquast:webagg_blit_fix

Conversation

Copy link
Copy Markdown
Contributor

PR summary

This PR is intended to address the problem of event-accumulation during image-processing in the webagg backend
which can result in an extreme lag that makes "fast updated" events like motion_notify_event etc. unusable at the moment.

Not 100% sure, but this might also improve problems concerning blitting in jupyter-notebooks (e.g. #19116) but would require sending "ack" messages in ipympl. The implementation is made in a way such that ipympl (or more generally backends that don't send "ack" messages) are not affected.

The following gifs show the outcome of this change: (left: current behavior, right: result of this PR)

🐍 code to run example
import matplotlib as mpl
mpl.use("webagg")
mpl.rcParams['webagg.port']=8988
mpl.rcParams['webagg.open_in_browser']=True

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(14, 8))
ax.plot([0, 1], [0, 1], 'r')
ln, = ax.plot([0, 1], [0, 0], 'g', animated=True)
ax.figure.canvas.draw()

fig._last_blit_bg = fig.canvas.copy_from_bbox(ax.bbox)

def on_resize(event):
    ax.figure.canvas.draw()
    fig._last_blit_bg = fig.canvas.copy_from_bbox(ax.bbox)

def on_move(event):
    ax.figure.canvas.restore_region(fig._last_blit_bg)
    ln.set_ydata([event.ydata, event.ydata])
    ax.draw_artist(ln)
    ax.figure.canvas.blit(ax.bbox)

fig.canvas.mpl_connect('motion_notify_event', on_move)
fig.canvas.mpl_connect('resize_event', on_resize)

plt.show()

PR checklist

Copy link
Copy Markdown
Member

Comments from call:

  • add ability to opt-in to this behavior with a string control (so we can support other stratgies)
  • look into de-bouncing in blit as well

attn @ianhi

raphaelquast mentioned this pull request Dec 7, 2023
14 of 30 tasks

ghost commented Sep 25, 2024

Copy link
Copy Markdown

I am using an interactive ipympl widget in an application, that would profit a lot from blitting, so i have been waiting for this PR to be merged. Thank you for the promising work done.
I just wanted to ask now, if we can expect this to be merged eventually, or if development has stopped, or is happening somewhere else, or ... ?

Copy link
Copy Markdown
Contributor Author

Hey, just a quick comment from my side:
I would be really happy if this PR is merged sometime soon...
Unfortunately however, I have absolutely no time right now to continue working on the remaining issues that need to be resolved and it will stay this way for a few months more...

I am happy if someone takes over in the meantime, otherwise I'll try to continue working on it as soon as i find some time (best guess is sometime early next year).

@sjmarwitz you could also monkey-patch the fix in the meantime to check if it does the job for you... I implemented a workaround for EOmaps ( see here)

ghost commented Sep 26, 2024 •
edited by ghost
Loading

Copy link
Copy Markdown

@raphaelquast Thanks for your quick response and for pointing me to your monkey-path fix. I tried it and immediately hit the problem with ipympl, that was already mentioned in the PR summary. Actually, when using ipympl, after the initial display of a figure, it won't update the canvas/figure, not even zooming or panning is possible. It seems, no 'ack' messages are being received (and sent?).

I would have liked to contribute a fix somehow, given the limited amount of time i have, but looking into the ipympl code, i got lost, as i don't "speak" js and the like and are not familiar with web technologies.


# Keep track of the number of received ack messages.
if self._num_received_images is None:
self._num_received_images = 0 # To support no "ack" messages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Don't know what this comment means.

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
raphaelquast and others added 2 commits March 5, 2025 09:39
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL