[19068] in s-news-athena

home help back first fref pref prev next nref lref last post

RE: [S] Problem with function from 3.3 to 4.+: slow plotting and no

daemon@ATHENA.MIT.EDU (Mark Bravington FSMG CEFAS)
Tue Aug 31 04:48:20 1999

Date: Sun, 29 Aug 1999 17:44:38 +0100
From: Mark Bravington FSMG CEFAS <M.V.Bravington@cefas.co.uk> (DN=MVB00, 
      RECIPIENTS, LOWESTOFT, CEFAS)
Message-Id: <"/GUID:51C66B92145AD311A6470000F84AA40F*"@MHS>
To: "'s.news'" <s-news@wubios.wustl.edu>,
        "'Sara Adlerstein'" <hy4a006@rzaixsrv2.rrz.uni-hamburg.de>


Dear Sara & others:

The speed problem-- let us not beat about the bush, it's a BUG-- is that whenever a new thing is plotted on a graph, SPLUS 4.0 & up insist on redrawing EVERYTHING that has been plotted so far in sequence, finally adding the new thing. So if you are plotting lines within a "for"-loop that executes N times, SPLUS will do N^2 redraws! This is happens whether you use editable or so-called "fast" graphics. It's exasperating because things used to work just fine under 3.3.

In Sara's example, the thing to do would be to code up single giant vectors x and y, with NAs separating the gaps between the bits that aren't to be joined up, then plot it all at once with one call to "lines". I have done this to produce an Splus version of the western European coastline, encoded as a list with components "x" and "y" with NAs to signify islands; this can be plotted by a single call to "lines( map.w.europe$coastline)".

However, this doesn't fix the clipping problem (another thing that used to work fine). I use the following code as a rough workaround:

Define a function "%in.range%" like this:

function( a, b)  
    (a >= min( b)) & (a <= max( b))

and a function "clippoly" like this:

function( xy, pu=par( 'usr')) {
  gap_ is.na( xy[,1])
  ind_ 1 + cumsum( gap)
  ind[ gap]_ ind[ gap]-1
  included_ xy[,1] %in.range% pu[1:2] & xy[,2] %in.range% pu[3:4]
  keep.poly_ sapply( split( included, ind), any, na.rm=T)
  
  xy_ xy[ keep.poly[ ind],]
  xy[ ,1]_ pmax( pu[ 1], pmin( xy[ ,1], pu[ 2]))
  xy[ ,2]_ pmax( pu[ 3], pmin( xy[ ,2], pu[ 4]))
  xy
}

(NB re other correspondence: I find underscores easier & less buggy to read and write than <- !)

Then I can plot western European coastline between -3 & +5 longitude, 49 and 56 latitude like this:

> plot( 0, 0, type='n', xlim=c( -3, 5), ylim=c( 49, 56)) # just the axes
> lines( clippoly( map.w.europe$coastline)) # nicely clipped
> polygon( clippoly( map.w.europe$coastline)) # if you want filled-in landmasses.

Note that "clippoly" doesn't work well unless the line segments are pretty short, because it bends the lines as well as clipping them. But it's fast & simple.

I have been forcibly reminded of these problems during the last week, as I have been running simulations within Splus and trying to see how various quantities change as the simulation evolves. It turns out to be far quicker to re-plot the entire graph each time, than to overdraw the old line and plot the new line; but the screen flickers like billy-o and it must be very inefficient to redo all the axis plotting etc. etc. every time. I have notified MathSoft of this problem in the past. I haven't installed Splus 2000 yet, and these problems may now have been remedied; if so, thank you to whoever fixed it!

Hope this helps

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

home help back first fref pref prev next nref lref last post