navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top HandlingData.html#HandlingData Gri: combining columns Gri: complete list of commands index.html#Top Gri: complete list of commands

8.12.5: Plotting several y-columns versus on x-column

Sometimes you'll have a datafile with the first column being x, and the other columns being various things to plot versus x. For example, you might have the data


1  8 11  9
2 22 21 20
3 11 10  9
4 20 15 10

in a file called `test.dat'. Let's say the x-column is time, and the y-columns are the readings from three temperature sensors. The following illustrates how you might plot these data. If you think the new-command which starts this script is useful, just insert it in your `~/.grirc' file and you can just use it without re-defining it each time. This will give Gri a command called `draw curves'.


`draw curves \xname \y1name ...'
Draw multiple y columns versus an x column.  Assumes
that the datafile is open, and that x is in the first
column, with the y values in one or more following 
columns.

The number of columns is figured out from the options, as is the name of the x-axis, and the labels to be used on each of the y curves. { # NB. the 3 below lets us skip the words 'draw' # and 'curves', and the name of the x-column. .num_of_y_columns. = {rpn wordc 3 -} if {rpn .num_of_y_columns. 1 >} show "ERROR: `draw curves' needs at least 1 y column!" quit end if

set x name {rpn 2 wordv} set y name ""

# Loop through the columns. .col. = 0 while {rpn .num_of_y_columns. .col. <} # The x-values will be in column 1, with y-values # in columns 2, 3, ..., of the file. .ycol. = {rpn .col. 2 +} rewind read columns x=1 y=.ycol. # At this point, you may want to change line thickness, # thickness, color, dash-type, etc. For illustration, # let's set dash type to the column number. set dash .col. draw curve draw label for last curve {rpn .col. 3 + wordv} .col. += 1 end while }

open test.dat draw curves time y1 y2 y3

navigation map