I'm attempting my first wxPython program in years (I'm a long time
Python programmer, but typically do server side work that needs no
GUI), and having some trouble with performance.
The system we're developing is connected to a 3-axis accelerometer,
streaming data to us at 1Khz (ie 1000 times a second). Each of those
1000 times a second, we receive an X coordinate, a Y coordinate and a
Z.
What we'd like to do is display three plots, in realtime, at a
framerate of roughly 20fps. Three plots consisting of XvsY, YvsZ and
XvsZ, and three of the raw X, Y and Z data.
Our first run at it was using matplotlib with wx, but the update was
horrendous (roughly 2 fps).
I figure that's too much overhead, so I'm now trying a more "raw"
method. For now, I'm just drawing one graph, to see how things go. I'm
using a wx.Frame, and a separate thread posting events to it. My basic
drawing code is:
def Draw(self, DC):
DC = wx.PaintDC(self)
DC.SetBackground(wx.Brush("White"))
DC.Clear()
GC = wx.GraphicsContext.Create(DC)
Pen = GC.CreatePen(wx.Pen("Black", 4))
c1 = wx.Color(255, 0, 0, 255)
c2 = wx.Color(255, 0, 0, 0)
GC.SetPen(Pen)
GC.Translate(60,75)
GC.Scale(0.5,0.5)
GC.DrawLines(self.points)
I update self.points in the event handler, and it will always consist
of 500 (X,Y) tuples. So essentially, I'm trying to draw a 500 point
line 20 times per second.
Is this the best way to do this? Anyone have any hints for going
faster, and using less CPU? Currently, I'm hitting 80% on one of my
processors. I'm running a 2GHz MacBook running OS X, with the latest
version of wxPython, and Python2.5.
Thanks in advance,
Jay P.