From: Russell E. O. <ro...@ce...> - 2005-03-16 21:13:02
|
I have appended some code which draws a varying pcolor plot in a Tkinter window. The plot shows two 5x5 white rings which shrink to 3x3 and then 1x3, then cycles through this repeatedly. Unfortunately, it slows down with each cycle!!! Are we doing something wrong? Or can we work around the problem somehow? (By the way, I did not write the code, though I cleaned up some portions of it. I realize the data generation can be cleaned up, but it's not slowing things down). -- Russell P.S. At risk of distracting from the main problem: I am not entirely sure I'm commanding a redraw in the correct fashion. I'm fuzzy on the difference between show and plot. Using canvas.show() and canvas.plot() both seem to work. Just calling plot() doesn't. Any hints on this or pointers to documentation would be appreciated. Also, is pcolor documented anywhere? ----- the code ----- import Tkinter as Tk from matplotlib.pylab import * import matplotlib.numerix as num from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg root = Tk.Tk() a =[ [0,1,2,3,4,5,6,\ 90,91,92,93,94,95,96,15,30,45,\ 60,75,21,36,51,66,81,\ 8,9,10,11,12,13,14,98,99,\ 100,101,102,103,104,\ 23,38,53,68,83,29,44,59,74,89],\ [16,17,18,19,20,76,77,78,79,80,35,50,65,\ 31,46,61,24,25,26,27,28,\ 84,85,86,87,88,39,54,69,43,58,73],\ [32,33,34,62,63,64,47,49,40,41,42,\ 70,71,72,55,57],\ [48,56] ] ioff() f = figure(figsize=(3,3)) sp = f.add_subplot(111) canvas = FigureCanvasTkAgg(f, master=root) canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) def displayData(maxCount=20, delayTimeMS=20, count=0): fx = count % len(a) a[fx].sort() ra = [] cnt = 0 v = a[fx][cnt] for i in range(15*15): if i == v: ra.append(1) cnt += 1 if cnt < len(a[fx]): v = a[fx][cnt] else: ra.append(0) z = num.reshape(ra, (15,15)) sp.pcolor(transpose(z), cmap=cm.gray, norm=normalize()) canvas.draw() count += 1 if count < maxCount: root.after(delayTimeMS, displayData, maxCount, delayTimeMS, count) displayData(maxCount=100, delayTimeMS=20) root.mainloop() |
From: Perry G. <pe...@st...> - 2005-03-16 23:00:16
|
My guess is that the hold mode is true (that's the default). I think this means that every time you call .pcolor that you are just appending another one to the axes. You should either change the default hold mode or call the .clear() method of the axes object before calling the .pcolor method. If you don't do that it is rendering n previous versions and the time it takes grows linearly. Perry On Mar 16, 2005, at 2:47 PM, Russell E. Owen wrote: > I have appended some code which draws a varying pcolor plot in a > Tkinter > window. The plot shows two 5x5 white rings which shrink to 3x3 and then > 1x3, then cycles through this repeatedly. > > Unfortunately, it slows down with each cycle!!! > > Are we doing something wrong? Or can we work around the problem > somehow? > > (By the way, I did not write the code, though I cleaned up some > portions > of it. I realize the data generation can be cleaned up, but it's not > slowing things down). > > -- Russell > > P.S. At risk of distracting from the main problem: I am not entirely > sure I'm commanding a redraw in the correct fashion. I'm fuzzy on the > difference between show and plot. Using canvas.show() and canvas.plot() > both seem to work. Just calling plot() doesn't. Any hints on this or > pointers to documentation would be appreciated. > > Also, is pcolor documented anywhere? > > ----- the code ----- > > import Tkinter as Tk > from matplotlib.pylab import * > import matplotlib.numerix as num > from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, > NavigationToolbar2TkAgg > > root = Tk.Tk() > a =[ [0,1,2,3,4,5,6,\ > 90,91,92,93,94,95,96,15,30,45,\ > 60,75,21,36,51,66,81,\ > 8,9,10,11,12,13,14,98,99,\ > 100,101,102,103,104,\ > 23,38,53,68,83,29,44,59,74,89],\ > [16,17,18,19,20,76,77,78,79,80,35,50,65,\ > 31,46,61,24,25,26,27,28,\ > 84,85,86,87,88,39,54,69,43,58,73],\ > [32,33,34,62,63,64,47,49,40,41,42,\ > 70,71,72,55,57],\ > [48,56] ] > > ioff() > f = figure(figsize=(3,3)) > sp = f.add_subplot(111) > canvas = FigureCanvasTkAgg(f, master=root) > canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) > > def displayData(maxCount=20, delayTimeMS=20, count=0): > fx = count % len(a) > a[fx].sort() > ra = [] > cnt = 0 > v = a[fx][cnt] > for i in range(15*15): > if i == v: > ra.append(1) > cnt += 1 > if cnt < len(a[fx]): > v = a[fx][cnt] > > else: > ra.append(0) > > z = num.reshape(ra, (15,15)) > sp.pcolor(transpose(z), cmap=cm.gray, norm=normalize()) > canvas.draw() > count += 1 > if count < maxCount: > root.after(delayTimeMS, displayData, maxCount, delayTimeMS, > count) > > displayData(maxCount=100, delayTimeMS=20) > root.mainloop() > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real > users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: John H. <jdh...@ac...> - 2005-03-16 23:21:57
|
>>>>> "Perry" == Perry Greenfield <pe...@st...> writes: Perry> My guess is that the hold mode is true (that's the Perry> default). I think this means that every time you call Perry> .pcolor that you are just appending another one to the Perry> axes. You should either change the default hold mode or Perry> call the .clear() method of the axes object before calling Perry> the .pcolor method. If you don't do that it is rendering n Perry> previous versions and the time it takes grows linearly. Good catch Perry. You need sp.hold(False) >> P.S. At risk of distracting from the main problem: I am not >> entirely sure I'm commanding a redraw in the correct >> fashion. I'm fuzzy on the difference between show and >> plot. Using canvas.show() and canvas.plot() both seem to >> work. Just calling plot() doesn't. Any hints on this or >> pointers to documentation would be appreciated. Se http://matplotlib.sourceforge.net/faq.html#SHOW >> Also, is pcolor documented anywhere? From the python shell In [1]: fig = figure() In [2]: sp = fig.add_subplot(111) In [3]: help(sp.pcolor) All the class docs can be found at http://matplotlib.sourceforge.net/classdocs.html. In particular, http://matplotlib.sourceforge.net/matplotlib.axes.html#Axes-pcolor >> ----- the code ----- Your code was improperly line wrapped and hence I had to edit it to test it. Please check that when you paste code in, it does not improperly wrap. Hope this helps, JDH |
From: Russell E. O. <ro...@ce...> - 2005-03-18 19:58:25
|
In article <m3r...@pe...>, John Hunter <jdh...@ac...> wrote: > >>>>> "Perry" == Perry Greenfield > >>>>> <pe...@st...> writes: > > Perry> My guess is that the hold mode is true (that's the > Perry> default). I think this means that every time you call > Perry> .pcolor that you are just appending another one to the > Perry> axes. You should either change the default hold mode or > Perry> call the .clear() method of the axes object before calling > Perry> the .pcolor method. If you don't do that it is rendering n > Perry> previous versions and the time it takes grows linearly. > > Good catch Perry. You need > > sp.hold(False) Thank you both very much. That did the trick. I put a hold on the figure and then a hold(False) on the one axis for which I wanted it and all works well now. > >> P.S. At risk of distracting from the main problem: I am not > >> entirely sure I'm commanding a redraw in the correct > >> fashion. I'm fuzzy on the difference between show and > >> plot. Using canvas.show() and canvas.plot() both seem to > >> work. Just calling plot() doesn't. Any hints on this or > >> pointers to documentation would be appreciated. > > See http://matplotlib.sourceforge.net/faq.html#SHOW Thanks. That was helpful -- though also a bit confusing, in that I'm using the TkAgg back end and calling pylab.draw() doesn't update anything visible on my FigureCanvasAgg object. (As an aside, calling show() on my FigureCanvasAgg object seems to work -- the code originally did that when I got it -- but the manual and FAQ clearly point to using draw instead). > >> Also, is pcolor documented anywhere? >... > All the class docs can be found at > http://matplotlib.sourceforge.net/classdocs.html. In particular, That's what I was really missing. Thanks! Now that I know about it, I'm not sure how I missed it the first time. Oh well... -- Russell |
From: John H. <jdh...@ac...> - 2005-03-18 21:36:04
|
>>>>> "Russell" == Russell E Owen <ro...@ce...> writes: Russell> Thanks. That was helpful -- though also a bit confusing, Russell> in that I'm using the TkAgg back end and calling Russell> pylab.draw() doesn't update anything visible on my Russell> FigureCanvasAgg object. (As an aside, calling show() on Russell> my FigureCanvasAgg object seems to work -- the code Russell> originally did that when I got it -- but the manual and Russell> FAQ clearly point to using draw instead). I looked back over the code you posted previously and see that you are using the API, eg making your own tk canvases. In this case you should not import pylab at all. Do everything from the class API. Call canvas.draw() rather than pylab.draw(). You can still use matplotlib.numerix to get all the Numeric/numarray symbols, but the pylab interface doesn't mix well with the API interface because pylab tries to manage figure creation and destruction for you. Instead of f = figure(figsize=(3,3)) # this is a pylab call sp = f.add_subplot(111) canvas = FigureCanvasTkAgg(f, master=root) do from matplotlib.figure import Figure f = Figure(figsize=(3,3)) # this is an API call sp = f.add_subplot(111) canvas = FigureCanvasTkAgg(f, master=root) See also examples/agg_oo.py and this post for a tutorial introduction the matplotlib API http://sourceforge.net/mailarchive/message.php?msg_id=11033442 Hope this helps, JDH |