From: Alan G I. <ai...@am...> - 2005-05-30 20:29:56
|
On Mon, 30 May 2005, John Hunter apparently wrote: > If possible, I suggest creating just two line objects and > manipulating their data directly, as in > from math import sin, cos > import matplotlib.numerix as nx > import pylab > pylab.ion() # interactive on, so each plot updates the window > pylab.hold('on') > allt = [0] # grow these lists and set the line data with them > allsin = [sin(0)] > allcos = [cos(0)] > lsin, = pylab.plot(allt, allsin, 'g+') # lsin is a Line2D instance > lcos, = pylab.plot(allt, allcos, 'ro') # lcos is a Line2D instance > pylab.xlabel('Time t[s]') > pylab.ylabel('Response') > pylab.axis([0,10,-1,1]) > for t in nx.arange(0.1,10,0.1): > allt.append(t) > allsin.append(sin(t)) > allcos.append(cos(t)) > lsin.set_data(allt, allsin) > lcos.set_data(allt, allcos) > pylab.draw() > # to prevent the window from closing > raw_input() 1. This is indeed much faster. 2. It still slows to a crawl as t grows. Should it? 3. The only thing that slows down is draw(), so the problem does not lie with the updating of the line instances. Alan Isaac P.S. Suppose I run the script and then press enter in the shell before closing the graph window. I get the following 'NULL tstate' error: Fatal Python error: PyEval_RestoreThread: Null tstate abnormal program termination Perhaps this is to be expected. |