question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mouse movement across canvas seems to trigger events even though all callbacks are cleared

See original GitHub issue

Hello, I must be missing something fundamental here, but the issue is the following:

Consider this MWE:

%matplotlib widget

import matplotlib.pyplot as plt

plt.ioff()
fig, ax = plt.subplots(figsize=(2, 2))
fig.canvas.toolbar_visible = False
fig.canvas.header_visible = False
fig.canvas.resizable = False

# Remove all callbacks
fig.canvas.callbacks.callbacks.clear()
fig.callbacks.callbacks.clear()
ax._propobservers = {}

ax.plot([1, 2, 3])
display(fig.canvas)

As expected, it draws a simple figure without header and toolbar into the notebook. However, even though I removed all callbacks that might be associated with this figure, its canvas, and the axes, moving the mouse cursor across the figure causes communication between front- and backend, which results in considerable data transfer (and, hence, jerkiness) when used over the internet. See this screen recording that demonstrates the issue:

https://youtu.be/M5mMzIGXT1s

It can also be seen that mouse clicks (indicated by the black circle) inside the canvas trigger communication as well.

How can I disable this behavior?

My system specifications:

  • ipympl 0.5.6
  • JupyterLab 2.0.1
  • Browser: Safari 13.1
  • OS: macOS Catalina 10.15.4

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hoechenbergercommented, Apr 10, 2020

I am wondering how other Matplotlib back-ends are behaving

No idea, I’m relatively inexperienced when it comes to Matplotlib internals. In any case, since ipympl is specifically designed for Jupyter Notebook use, and since Jupyter Notebooks are often deployed online on remote servers, behavior that might be unproblematic for other (locally running) backends could become an issue due to network latency and data transfer time. This just to say that: Even if other backends do act like I demonstrated in my MWE, ipympl should probably opt for a slightly different approach that’s more responsive and generates fewer data transfers.

1reaction
martinRenoucommented, Apr 10, 2020

Hello, thanks for opening an issue!

Indeed your code will not cancel the communication between the back-end and the front-end. I did not know there was an API for that in Matplotlib, and it’s not plugged to the widgets communication AFAIK.

@tacaswell do you think doing fig.canvas.callbacks.callbacks.clear() should cancel communication? If yes, should it only cancel mouse-related communication or all communication (resize, redraw etc).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set mousemove update speed? - javascript
You can't. The mousemove events are generated by the browser, and thus you are receiving them as fast as the browser is generating...
Read more >
Event handling and picking — Matplotlib 3.6.2 documentation
The canvas retains only weak references to instance methods used as callbacks. Therefore, you need to retain a reference to instances owning such...
Read more >
Follow the Mouse Cursor - KIRUPA
The fix is to clear out everything in the canvas before drawing our circle at its new position, and that is much more...
Read more >
Using Touch Events with the HTML5 Canvas - Ben Centra
What's not so easy is getting the canvas to work with both mouse and touch events, a requirement for mobile-friendly applications.
Read more >
Button UI Not Working with The new Input system - Unity Forum
Added my own button to the mix, clicking or even mouse over events aren't detected, like something is blocking the entire canvas.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found