8000 nbagg backend incredibly laggy in IPython notebook · Issue #6850 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
nbagg backend incredibly laggy in IPython notebook #6850
Closed as not planned
Closed as not planned
@alexanderwhatley

Description

@alexanderwhatley
  • 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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUI: nbaggstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0