Next: ellipse() Up: Graphics Macros Help File Previous: contour()   Contents

contourplot()

Usage:
contourplot(x,y,vals,levels [,label:T] [,linefrom:T] [,draw:F]\
  [,save:T] [,graphics keywords]), REAL vectors x, y, levels, with
  no MISSING values, REAL matrix vals



Keywords: contour graphs
contourplot(x,y,vals,levels [,graphics keywords]) draws unlabelled
contours of a surface whose height z is known at points on a rectangular
grid defined by REAL vectors x and y.  The desired contour levels are
defined by REAL vector levels.  The height at (x[i],z[j]) is z =
vals[i,j].

The values of x and y must be distinct and non-MISSING.

vals must be a nrows(x) by nrows(y) REAL matrix and may have MISSING
elements.  Most commonly, vals[i,j] = F(x[i],y[j]) for some function
F(x,y) of two variables.  If the surface is not defined or is infinite
at (x[i],y[j]), vals[i,j] should be MISSING.

You can use most of the usual graphics keywords such as 'xlab', 'ylab',
'title', 'add' and 'show'.  In particular, you can use 'linetype' to
control the type of line drawn.  See topic 'graph_keys'.

contourplot(x,y,vals,levels, label:T [,graphics keywords]) does the same
except that you use the mouse to position labels for each contour line
that was actually drawn (some levels may be outside the minimum and
maximum values in vals).  A simple algorithm is used to find the contour
line whose level is nearest the interpolated value at the point you
click.  Then this level is printed at that point.  You can end labelling
by pressing 'q' when the crosshairs are in the graphics window.

contourplot(x,y,vals,levels, linefrom:T [,graphics keywords]) is another
way to label points.  You use the mouse to draw a line starting at the
contour and ending where the label is then printed.

contour uses macro findcontours() to locate and label contours.  You can
use findcontours() directly to label contours in a contour plot that was
previously drawn.  

result <- contourplot(x,y,vals,levels,save:T [,other keywords]) sets
result to structure(Contour_1:comp1,Contour_2:comp2 ...).  Component I
of result is structure(x:xvals, y:yvals,level:levels[I]).  When
level[I] is outside the range of values, xvals and yvals are NULL.
Otherwise they are the x- and y-values defining the intersections of the
contour with gridlines.

You could use this returned structure to add the same contour curves to
another graph.  The following example might be appropriate when the
contours were those of an estimated bivariate density function based on
a bivariate sample hconcat(xvals, yvals), where xvals and yvals are REAL
vectors.

  Cmd> chplot(xvals, yvals, symbols:"\7",show:F) #scatter plot of sample

  Cmd> for(i,1,levels){
          @comp <- result[i]
          if (!isnull(@comp$x)){
            lineplot(keys:strconcat(@comp,add:T,show:F))
          }
       }

  Cmd> showplot(xmin:?,ymin:?,xmax:?,ymax:?) # display the plot

In place of 'save:T' you could use 'draw:F'.  With both 'save:T' and
'draw:T' the contours are both drawn and returned in a structure.

contourplot() requires macros contour(), findcontour() and _Follow().
They are read in automatically if necessary and possible.

See also contour() and findcontour().


Gary Oehlert 2003-01-15