slowdown when using pcolor and TkAgg; help?

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()

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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users