I isolated the problem a bit more. For some reason drawing gets slower and slower with each plot drawn.
from os import sys from time import time from PyQt4 import QtGui, QtCore import matplotlib matplotlib.use('QT4Agg') from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure class MyMplCanvas(FigureCanvas): """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).""" def __init__(self, parent=None, width=5, height=4, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(111) # We want the axes cleared every time plot() is called self.axes.hold(False) self.compute_initial_figure() # FigureCanvas.__init__(self, fig) self.setParent(parent) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) def compute_initial_figure(self): pass class MyDynamicMplCanvas(MyMplCanvas): """A canvas that updates itself every second with a new plot.""" def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) timer = QtCore.QTimer(self) QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure) timer.start(0) self.firstrun = True self.colorbar = None self.time = time() self.p = None def compute_initial_figure(self): pass def update_figure(self): self.p = self.axes.scatter([1,2,3],[4,5,6], c = range(3), animated=True) self.axes.set_xlabel('psi') self.axes.set_ylabel('delta') if self.firstrun == True: self.colorbar = self.axes.figure.colorbar(self.p) self.firstrun = False self.colorbar.set_clim(vmin=0,vmax=2) self.colorbar.draw_all() self.colorbar.set_label('time [abtr. ]') self.draw() newtime = time() print newtime - self.time self.time = newtime class ApplicationWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.main_widget = QtGui.QWidget(self) l = QtGui.QVBoxLayout(self.main_widget) dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100) l.addWidget(dc) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) qApp = QtGui.QApplication(sys.argv) aw = ApplicationWindow() aw.setWindowTitle("%s" % "Slow!") aw.setGeometry(100,100,800,600) aw.show() sys.exit(qApp.exec_()) On Mon, Jan 4, 2010 at 3:36 PM, Alexander Hupfer <son...@gmail.com> wrote: > Ok, here is the code as a whole. I think it's still short enough to > ilustrate the problem. Just start it with the datafile "elips" as an > argument > > http://dl.dropbox.com/u/226980/elipsometry.tar.gz > > The timer shows how long each render cycle takes. The time seems to grow > with number of cycles rendered even when no more points are added (the > points are calculated with a continous rate in a background thread and are > about 300 total). > > > On Sun, Jan 3, 2010 at 8:16 PM, John Hunter <jdh2...@gmail.com> wrote: > >> On Sun, Jan 3, 2010 at 7:02 PM, Alexander Hupfer <son...@gmail.com> >> wrote: >> > Thanks I got it fixed. >> > This leads to the follow up question: >> > What is the right way to keep an application responsive while the graph >> is >> > drawn? >> > Drawing a scatter plot with 300 points seems to take a while. I guess I >> need >> > to launch the drawing in another thread but don't know exactly how to do >> > this and only find examples of doing calculations in the background and >> not >> > actual widget interaction. >> >> You posted some real code and a traceback, which helped move the ball >> forward. What we really need to see to help you though is a complete, >> free-standing example, that we can run on our machines, which exposes >> the problem. >> >> JDH >> > >
------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users