Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbagg backend incredibly laggy in IPython notebook #6850

Closed
1 task
alexanderwhatley opened this issue Jul 28, 2016 · 6 comments
Closed
1 task

nbagg backend incredibly laggy in IPython notebook #6850

alexanderwhatley opened this issue Jul 28, 2016 · 6 comments
Labels
GUI: nbagg status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@alexanderwhatley
Copy link

  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    Windows 10, Matplotlib 1.5.1, Python 3.5.2

I wrote some code for allowing the user to draw rectangles in a blank matplotlib graph using the nbagg backend in an IPython notebook, and it is incredibly laggy. Is this a current limitation, or is this perhaps a bug with the library? Here is the code I have:

import matplotlib
matplotlib.use("nbagg")
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from ipywidgets.widgets import Button
from IPython.display import display

class Test(object):
    def __init__(self):
        plt.ion()
        self.figure = plt.figure()
        self.ax = self.figure.gca()
        self.rect = Rectangle((0,0), 0, 0, color = '0', fill = False)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        # Graph interaction
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)

    def on_motion(self, event):
        if self.is_pressed:
            self.x1 = event.xdata
            self.y1 = event.ydata

            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
            self.rect.figure.canvas.draw()

    def on_press(self, event):
        self.is_pressed = 1
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.rect.set_visible(True)

    def on_release(self, event):
        self.is_pressed = 0
        self.ax.scatter(self.x_inside, self.y_inside, c = "red")
        self.figure.canvas.draw()
        self.rect.set_visible(False)
        self.rect.figure.canvas.draw()


test = Test()
@tacaswell
Copy link
Member

Remove all of the explicit calls to draw (or at least change them to draw_idle).

Please try the 2.0.0b3 beta, there are some speed improvements on that branch as well.

The killer is probably fully re-drawing the figure on every mouse motion. The toolbar has a draw_rubberband (which is what zoom uses) which draws the rectangle using the 'native' tools and is much more performant.

@watkinrt
Copy link
Contributor

watkinrt commented May 5, 2017

Does anyone know what makes the nbagg back so much slower than the other aggs with respect to event handling? I'm trying to do a similar draggable (motion_notify_event) interaction, but the latency makes it almost unusable. I've tried using blitting and draw_idle commands to speed things up, but they only help a little (at least, using Matplotlib 2.0.0).

@tacaswell
Copy link
Member

I suspect the latency is because the communication happening over a web-socket rather than within a process.

@thomasaarholt
Copy link

Is there anyone working on improving speeding up the notebook backend? The notebook backend is wonderful, but on Windows it is quite slow. I find that it is slower here than it is on Linux.

@tacaswell
Copy link
Member

Having someone pick up and finish #4290 may help with this.

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 5, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jul 5, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: nbagg status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

5 participants