[wxPython-users] Re: Draw method in PlotCanvas class for a number of points (>80,000) takes too much time

Christopher Barker Chris.Barker at noaa.gov
Tue Dec 19 10:02:14 PST 2006


maser rati wrote:
> I am wondering if the delay that I reported earlier
> could be due to reading the data from tuples?

it could be -- I don't remember if PlotCanvas uses numpy internally. 
However, as a numpy fan, I have a couple comments:


> I first initialize an empty array of type numpy with
> the H parameter. Then, I use the fromstring function
> to string the y data from the data file

fromstring() creates an array, so there is no need to initialize one 
first. I take it your data is in binary unsigned short format, in which 
case:

y = numpy.fromstring(string, dtype=numpy.ushort)

If you're reading from a file, you can do that in one step:

y = numpy.fromfile(file, dtype=numpy.ushort, count=NumY)

If the file is a text file:

y = numpy.fromfile(file, dtype=numy.ushort, count=NumY, sep=',')

The sep parameter tells fromfile what the separator is in your text file.

> I then append the
> xdata to each element of the y array, creating a
> series of x,y tuples, of the format
> [(x1,y1),(x2,y2)....]

where does the x data come from? If it's also in a file, read it in like 
the y data, then put the two together like so:

Points = numpy.hstack((x.reshape(-1,1),y.reshape(-1,1)))

the reshape() calls make sure the x and y arrays are column vectors, so 
that when you put them together with hstack (horizontal stack), you get 
a NX2 array, which is what you want.

NOTE: I recommend joining the numpy mailing list, and buying the numpy book.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list