GRAP(1)                                                   GRAP(1)

     NAME
          grap - pic preprocessor for drawing graphs

     SYNOPSIS
          grap [ file ... ]

     DESCRIPTION
          Grap is a pic(1) preprocessor for drawing graphs on a type-
          setter.  Graphs are surrounded by the troff `commands' .G1
          and .G2.  Data are scaled and plotted, with tick marks sup-
          plied automatically.  Commands exist to modify the frame,
          add labels, override the default ticks, change the plotting
          style, define coordinate ranges and transformations, and
          include data from files.  In addition, grap provides the
          same loops, conditionals, and macro processing that pic
          does.

          frame ht e wid e top dotted ...: Set the frame around the
          graph to specified ht and wid; default is 2 by 3 (inches).
          The line styles (dotted, dashed, invis, solid (default)) of
          the sides (top, bot, left, right) of the frame can be set
          independently.

          label side "a label" "as a set of strings" adjust: Place
          label on specified side; default side is bottom.  adjust is
          up (or down left right) expr to shift default position;
          width expr sets the width explicitly.

          ticks side in at optname expr, expr, ...: Put ticks on side
          at expr, ..., and label with "expr". If any expr is followed
          by "...", label tick with "...", and turn off all automatic
          labels.  If "..." contains %f's, they will be interpreted as
          printf formatting instructions for the tick value.  Ticks
          point in or out (default out).  Tick iterator: instead of at
          ..., use from expr to expr by op expr where op is optionally
          +-*/ for additive or multiplicative steps.  by can be omit-
          ted, to give steps of size 1.  If no ticks are requested,
          they are supplied automatically; suppress this with ticks
          off.  Automatic ticks normally leave a margin of 7% on each
          side; set this to anything by margin = expr.

          grid side linedesc at optname expr, expr, ...: Draw grids
          perpendicular to side in style linedesc at expr, .... Itera-
          tors and labels work as with ticks.

          coord optname x min, max y min, max log x  log y: Set range
          of coords and optional log scaling on either or both.  This
          overrides computation of data range.  Default value of
          optname is current coordinate system (each coord defines a
          new coordinate system).

     Page 1                       Plan 9            (printed 11/18/24)

     GRAP(1)                                                   GRAP(1)

          plot "str" at point; "str" at point: Put str at point. Text
          position can be qualified with rjust, ljust, above, below
          after "...".

          line from point to point linedesc: Draw line from here to
          there.  arrow works in place of line.

          next optname at point linedesc: Continue plot of data in
          optname to point; default is current.

          draw optname linedesc ...: Set mode for next: use this style
          from now on, and plot "..." at each point (if given).

          new optname linedesc ...: Set mode for next, but disconnect
          from previous.

          A list of numbers x y1 y2 y3 ... is treated as plot bullet
          at x,y1; plot bullet at x,y2; etc., or as next at x,y1 etc.,
          if draw is specified.  Abscissae of 1,2,3,... are provided
          if there is only one input number per line.

          A point optname expr, expr maps the point to the named coor-
          dinate system.  A linedesc is one of dot dash invis solid
          optionally followed by an expression.

          define name {whatever}: Define a macro.  There are macros
          already defined for standard plotting symbols like bullet,
          circle, star, plus, etc., in /sys/lib/grap.defines, which is
          included if it exists.

          var = expr: Evaluate an expression.  Operators are + - * and
          /.  Functions are log and exp (both base 10), sin, cos,
          sqrt; rand returns random number on [0,1); max(e,e),
          min(e,e), int(e).

          print expr; print "...": As a debugging aid, print expr or
          string on the standard error.

          copy "file name": Include this file right here.

          copy thru macro: Pass rest of input (until .G2) through
          macro, treating each field (non-blank, or "...") as an argu-
          ment.  macro can be the name of a macro previously defined,
          or the body of one in place, like /plot $1 at $2,$3/.

          copy thru macro until "string": Stop copy when input is
          string (left-justified).

          pic remainder of line: Copy to output with leading blanks
          removed.

          graph Name pic-position: Start a new frame, place it at

     Page 2                       Plan 9            (printed 11/18/24)

     GRAP(1)                                                   GRAP(1)

          specified position, e.g., graph Thing2 with .sw at Thing1.se
          + (0.1,0).  Name must be capitalized to keep pic happy.

          .anything at beginning of line: Copied verbatim.

          sh %anything %: Pass everything between the %'s to the
          shell; as with macros, % may be any character and anything
          may include newlines.

          # anything: A comment, which is discarded.

          Order is mostly irrelevant; no category is mandatory.  Any
          arguments on the .G1 line are placed on the generated .PS
          line for pic.

     EXAMPLES
          .G1
          frame ht 1 top invis right invis
          coord x 0, 10 y 1, 3 log y
          ticks left in at 1 "bottommost tick", 2,3 "top tick"
          ticks bot in from 0 to 10 by 2
          label bot "silly graph"
          label left "left side label" "here"
          grid left dashed at 2.5
          copy thru / circle at $1,$2 /
          1 1
          2 1.5
          3 2
          4 1.5
          10 3
          .G2
          frame ht 1 top invis right invis
          coord x 0, 10 y 1, 3 log y
          ticks left in at 1 "bottommost tick", 2,3 "top tick"
          ticks bot in from 0 to 10 by 2
          label bot "silly graph"
          label left "left side label" "here"
          grid left dashed at 2.5
          copy thru / circle at $1,$2 /
          1 1
          2 1.5
          3 2
          4 1.5
          10 3

     FILES
          /sys/lib/grap.defines  definitions of standard plotting
                                 characters, e.g., bullet

     SOURCE
          /sys/src/cmd/grap

     Page 3                       Plan 9            (printed 11/18/24)

     GRAP(1)                                                   GRAP(1)

     SEE ALSO
          pic(1), troff(1)
          J. L. Bentley and B. W. Kernighan, ``GRAP-A Language for
          Typesetting Graphs'', Unix Research System Programmer's Man-
          ual, Tenth Edition, Volume 2.

     Page 4                       Plan 9            (printed 11/18/24)