Peter Wurmsdobler wrote:
as maybe many people, I want to make some oscilloscope type of plot. I
assume that some vector is updated by removing the first value and
appending a new value. Then that vector should be plotted which gives
the impression of a moving curve.I tried to implement the moving plot using, or perhaps mis-using
wxPyPlot with the following code. But I am convinced that there must be
a more elegant way, by just updating the data in the PolyLine and
calling a redraw method. Any ideas?
While the comments indicate that "all methods are private", the wonder
of PYthon is that attributes are not truly private, so, just as you
suspected, this works just fine:
def OnTimer(self,event):
self.count += self.dT
self.data1[:,1] = Numeric.sin(self.time+self.count) #fake move
self.lines1.points = self.data1
self.client.Draw(self.pg)
However, it's not really well optimised. One difficultly is that the
Draw() method currently contians all sorts of code for setting up and
drawing the axes. In your case, you want a Draw() function that just
re-draws the data, with all the Axis, zoom, etc all the same. It
shouldn't be too hard to separate those functions, however.
Someone else on this list was trying to optimize drawing in wxPyPlot,
and found that they could access the wxPyPlot dc directly, and draw to
that. It was a little messy, but it worked. Personlly, I'd just add the
functionality to wxPyPlot.
Another problem is that as you re-draw your data, you need to erase the
previous version, and restore the gridlines or whatever. This could sap
performance a little. In my FloatCanvas (which may be distributed with
the next version of wxPython...thanks, Robin) I solved this by triple
buffering... If an obejct get an "Foreground" flag, it gets drawn on top
of the usual off-screen buffer. THis way, you can have something
changing on top of a complex background, and not have to re-draw the
background each frame.
I've enclosed FloatCanvas.py and test_Plot.py, which produces something
very similar to your example. I'm not sure using FloatCanvas is right
for you (I havn't built an axis drawing or anything like that into it),
but you can get ideas from it.
-Chris
ยทยทยท
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov