Tkinter is extremely slow in drawing plots.... why???

Jørgen Cederberg jorgencederberg at
Thu Aug 29 09:43:27 CEST 2002

---- Original Message -----
From: "revyakin" <revyakin at>
Newsgroups: comp.lang.python
Sent: Wednesday, August 28, 2002 9:16 PM
Subject: Tkinter is extremely slow in drawing plots.... why???

> I am writing a simple application which is supposed to take an array
> of x,y coords, generate a plot and allow simple manipulations on the
> plot for convenient analysis(scrolling, scaling, zooming). I typically
> work with reltaively large
> sets of points, e.g. 65 000 (x,y) tuples. My problem is that , first,
> it
> takes it forever to draw a plot, and once the plot is in the window
> it's extremely slow in
> scrolling, zooming, resizing, etc. I don't have programming experience
> in optimizing applications, and I picked python since I've done some
> CGI based coding.  So I may not know smth that make my app work very
> inefficiently. Can I use python Tk at
> all for my purpose? Can anyone suggest what I can do to make it work
> faster?
> I generate plots as following:
> fileWindow = Toplevel()
> #       the following returns an array of (x,y) tuples from an
> external file.
> dataset = processData(data)
> scrollbar = Scrollbar(fileWindow,orient=HORIZONTAL)
> scrollbar.pack(side=BOTTOM, fill=Y,expand=YES)
> canvas = Canvas (master=fileWindow,height=600, width=800,
> xscrollcommand=scrollbar.set)
> canvas.pack()
> scrollbar.config(command=canvas.xview)
> for datum in dataset:
> item = canvas.create_line(datum[0], datum[1], datum[0]+1,
> datum[1]+1, fill = 'black')


I can at least suggest some improvements. Is your for loop correct? If it is
tuple of x,y coordinates (that I guess have been normalized to fit the
screen), why do you add one (1) to the values??

If the dataset is a set of tuples like:   ((x0,y0), (x1,y1), ... (xN-1,
yN-1)), you can type

item = apply(canvas.create_line, dataset, {'fill': 'black'})
or probably also
item = canvas.create_line(dataset, fill='black')

I have noticed several performance issues for datasets over a 1000 points,
and I think (not verified) that the drawing of lines are O(n^2) in running

I thought of splitting datasets into to smaller sets, but have never tested


Jorgen Cederberg

More information about the Python-list mailing list