[S] help with animation

Mark Bravington FSMG CEFAS (M.V.BRAVINGTON@cefas.co.uk)
Fri, 8 May 1998 11:28:57 +0100


I am fitting a curve iteratively in S-PLUS, and want to watch how the curve
changes as the iterations progress. This means making "real-time" changes to an
on-screen graph; I make one call to plot(...) to set up the graph before the
iterations begin, then at each iteration I erase the previous curve by using
lines( x, old.curve, col=0), and plot the new curve using lines( x, new.curve,
col=2). I also use mtext(...) to display information about the current state of
the iteration. A recent reply from Chuck Taylor of MathSoft, explained how to
use guiLocator( -0.0001) within each iteration, to immediately update the graph.

All this does work. But at each iteration, S-PLUS seems to run through _all_ the
previously-plotted points and lines, and all the mtexts, rather than just adding
the new commands to the plot. IE after the 50th iteration, S-PLUS has to plot
and erase 50 curves. For n iterations, S-PLUS 4.0 does of the order of n^2
plots. This can seriously slow things down-- imagine if you are trying to watch
the evolution of a dynamical system, or (to be more statistical) the output of a
filtering algorithm.

To illustrate the problem, I wrote the following simple function, and tried to
compare times under S-PLUS 3.3 and 4.0:

function(){
y_ x_ 1:10
plot( x, y, type='l')

for( i in 1:1000) {
lines( x, y, col=0)
y_ c( 2, rep( 2+i/1000, 9))
lines( x, y)
guiLocator(-0.0001) }

invisible( NULL)
}

This function took just a few seconds to execute in 3.3 (without the call to
guiLocator, of course). In 4.0, my system had only reached i~100 after a minute,
and S-PLUS refused to accept "ESCAPE" interrupts. (Which were much better as
CTRL-C, by the way-- less risk of confusion with the command-line meaning of
ESCAPE). I had to use Task Manager to close down S-PLUS 4.0.

In "Graph Options" (right-click on the graph), I have "command options/mode" set
to "fast" and "command options/page creation" set to "off". I'm using SPLUS 4.0
release 3 under Windows NT.

Does anyone have a fix? If not, MathSoft, can you sort this out for the next
release please? It is very tedious.

Mark Bravington
m.v.bravington@cefas.co.uk
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news