Closed as not planned
Description
- 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()