The Plotutils Package - Simple Examples

Go to the first, previous, next, last section, table of contents.

## Simple examples using `graph`

By default, `graph` reads ASCII data from the files specified on the command line, or from standard input if no files are specified. The data are pairs of numbers, interpreted as the x and y coordinates of data points:

    0.0  0.0
    1.0  0.2
    2.0  0.0
    3.0  0.4
    4.0  0.2
    5.0  0.6

Data points do not need to be on different lines, nor do the x and y coordinates of a data point need to be on the same line. However, there should be no blank lines in the input if it is to be viewed as forming a single dataset.

To plot such a dataset with `graph`, you could do

    graph -T ps ascii_data_file > plot.ps

or equivalently

    graph -T ps < ascii_data_file > plot.ps

This will produce an encapsulated Postscript file `plot.ps`, which you may include in another document, display on a screen, or send directly to a printer. (The ``--page-size'` option, or the `PAGESIZE` environment variable, specifies the size of the printed page. The default is "letter", i.e., 8.5in by 11in, but "a4" or other ISO or ANSI page sizes can be specified instead.)

You may also do

    graph -T fig < ascii_data_file > plot.fig

to produce a file `plot.fig` that you may edit with the the free `xfig` drawing editor, or

    graph -T ai < ascii_data_file > plot.ai

to produce a file `plot.ai` that you may edit with Adobe Illustrator. If you do

    graph -T hpgl < ascii_data_file > plot.plt

you will produce a file `plot.plt` in the Hewlett--Packard Graphics Language (HP-GL/2) that you may send to a Hewlett--Packard plotter. Similarly, you may use `graph -T pcl` to produce a file in PCL 5 format that may be printed on a LaserJet or other laser printer.

You may use `graph -T X` to pop up a window on an X Window System display, and display the plot in it. For that, you would do

    graph -T X < ascii_data_file

If you use `graph -T X`, no output file will be produced; only a window. The window will vanish if you type ``q'` or click your mouse in it.

You may also use `graph -T pnm` to produce a PNM file (a "portable anymap"), and `graph -T gif` to produce a pseudo-GIF file. If the free image display application `xv` is available on your system, you would use either of the two commands

    graph -T pnm < ascii_data_file | xv -
    graph -T gif < ascii_data_file | xv -

to display the output file.

Another thing you can do is use `graph -T tek` to display a plot on a device that can emulate a Tektronix 4014 graphics terminal. `xterm`, the X Window System terminal emulator, can do this. Within an `xterm` window, you would do

    graph -T tek < ascii_data_file

`xterm` normally emulates a VT100 terminal, but when this command is issued from within it, it will pop up a second window (a `Tektronix window') and draw the plot in it. The Japanese terminal emulator `kterm` should be able to do the same, provided that it is correctly installed. Another piece of software that can emulate a Tektronix 4014 terminal is the MS-DOS version of `kermit`.

`graph` may behave differently depending on the environment in which it is invoked. We have already mentioned the `PAGESIZE` environment variable, which affects the operation of `graph -T ai`, `graph -T ps`, `graph -T fig`, `graph -T pcl`, and `graph -T hpgl`. Similarly, the `BITMAPSIZE` environment variable affects the operation of `graph -T X`, `graph -T pnm`, and `graph -T gif`. The `DISPLAY` environment variable affects the operation of `graph -T X`, and the `TERM` environment variable affects the operation of `graph -T tek`. There are also several environment variables that affect the operation of `graph -T pcl` and `graph -T hpgl`. For a complete discussion of the effects of the environment on `graph`, see section Environment variables. The following remarks apply irrespective of which output format is specified.

By default, successive points in the dataset are joined by solid line segments, which form a polygonal line or polyline that we call simply a `line'. You may choose the style of line (the `linemode') with the ``-m'` option:

    graph -T ps -m 2 < ascii_data_file > plot.ps

Here ``-m 2'` indicates that linemode #2 should be used. If the dataset is rendered in monochrome, which is the default, the line can be drawn in one of five distinct styles. Linemodes #1 through #5 signify solid, dotted, dotdashed, shortdashed, and longdashed; thereafter the sequence repeats. If the ``-C'` option is used, the dataset will be rendered in color. For colored datasets, the line can be drawn in one of 25 distinct styles. Linemodes #1 through #5 signify red, green, blue, magenta, and cyan; all are solid. Linemodes #6 through #10 signify the same five colors, but dotted rather than solid. Linemodes #11 through #16 signify the same five colors, but dotdashed, and so forth. After linemode #25, the sequence repeats. Linemode #0, irrespective of whether the rendering is in monochrome or color, means that the line is not drawn.

If you wish to fill the polygon bounded by the line (i.e., shade it, or fill it with a solid color), you may use the ``-q'` option. For example,

    echo .1 .1 .1 .9 .9 .9 .9 .1 .1 .1 | graph -T ps -C -m 1 -q 0.3 > plot.ps

will plot a square region with vertices (0.1,0.1), (0.1,0.9), (0.9,0.9), and (0.9,0.1). The repetition of the first vertex (0.1,0.1) at the end of the sequence of vertices ensures that the square will be closed: all four segments of its boundary will be drawn. The square will be drawn in red, since the colored version of linemode #1 is requested. The interior of the square will be filled with red to an intensity of 30%, as the ``-q 0.3'` option specifies. If the intensity were zero, the region would be filled with white, and if it were 1.0, the region would be filled with solid color. If the intensity were negative, the region would be unfilled, or transparent (the default).

You may choose the thickness (`width') of the line, whether it is filled or not, by using the ``-W'` option. For example, ``-W 0.01'` specifies that the line should have a thickness equal to 0.01 times the size of the display. Also, you may put symbols at each data point along the line by doing, for example,

    graph -T ps -S 3 0.1 < ascii_data_file > plot.ps

where the first argument 3 indicates which symbol to plot. The optional second argument 0.1 specifies the symbol size as a fraction of the size of the `plotting box': the square within which the plot is drawn. Symbol #1 is a dot, symbol #2 is a plus sign, symbol #3 is an asterisk, symbol #4 is a circle, symbol #5 is a cross, and so forth. (See section Available marker symbols.) Symbols 1 through 31 are the same for all display types, and the color of a symbol will be the same as the color of the line it is plotted along.

Actually, you would probably not want to plot symbols at each point in the dataset unless you turn off the line joining the points. For this purpose, the `negative linemode' concept is useful. A line whose linemode is negative is not visible; however, any symbols plotted along it will have the color associated with the corresponding positive linemode. So, for example,

    graph -T ps -C -m -3 -S 4 < ascii_data_file > plot.ps

will plot a blue circle at each data point. The circles will not be joined by line segments. By adding the optional second argument to the ``-S'` option, you may adjust the size of the circles.

`graph` will automatically generate abscissa (i.e., x) values for you if you use the ``-a'` option. If this option is used, no abscissa values should be given in the data file. The data points will be taken to be regularly spaced along the abscissa. The two arguments following ``-a'` on the command line will be taken as the sampling interval and the abscissa value of the first data point. If they are absent, they default to 1.0 and 0.0 respectively. For example, the command

    echo 0 1 0 | graph -T ps -a > plot.ps

produces exactly the same plot as

    echo 0 0 1 1 2 0 | graph -T ps > plot.ps

`graph` will plot data with error bars, if the ``-I e'` option is specified. If it is, the dataset should consist of triples (x,y,error) rather than pairs (x,y). A vertical error bar of the appropriate length will be plotted at each data point. You may plot a symbol at each data point, along with the error bar, by using the ``-S'` option in the usual way. The symbol will be the same for each point in the dataset. You may use the ``-a'` option in conjunction with ``-I e'`, if you wish. If you do, the dataset should contain no abscissa (i.e., x) values.

By default the limits on the x and y axes, and the spacing between the labeled ticks on each axis, are computed automatically. You may wish to set them manually. You may accomplish this with the ``-x'` and ``-y'` options.

    echo 0 0 1 1 2 0 | graph -T ps -x -1 3 -y -1 2 > plot.ps

will produce a plot in which the x axis extends from -1 to 3, and the y axis from -1 to 2. By default, `graph` tries to place about six numbered ticks on each axis. By including an optional third argument to either ``-x'` or ``-y'`, you may manually set the spacing of these ticks, also. For example, using ``-y -1 2 1'` rather than ``-y -1 2'` will produce a y axis with labeled ticks at -1, 0, 1, and 2, rather than at the locations that `graph` would choose by default, which would be -1, -0.5, 0, 0.5, 1, 1.5, and 2. In general, if a third argument is present then labeled ticks will be placed at each of its integer multiples.

To make an axis logarithmic, you may use the ``-l'` option. For example,

    echo 1 1 2 3 3 1 | graph -T ps -l x > plot.ps

will produce a plot in which the x axis is logarithmic, but the y axis is linear. To make both axes logarithmic, you would use ``-l x -l y'`. By default, the upper and lower limits on a logarithmic axis are powers of ten, and there are tick marks at each power of ten and at its integer multiples. The tick marks at the powers of ten are labeled. If the axis spans more than five orders of magnitude, the tick marks at the integer multiples are omitted.

If you have an unusually short logarithmic axis, you may need to increase the number of labeled ticks. To do this, you should specify a tick spacing manually. For example, ``-l x -x 1 9 2'` would produce a plot in which the x axis is logarithmic and extends from 1 to 9. Labeled ticks would be located at each integer multiple of 2, i.e., at 2, 4, 6, and 8.

You may label the x and y axes with the ``-X'` and ``-Y'` options, respectively. For example,

    echo 1 1 2 3 3 1 | graph -T ps -l x -X "A Logarithmic Axis" > plot.ps

will label the log axis in the preceding example. By default the label for the y axis (if any) will be rotated 90 degrees, unless you use the ``--toggle-rotate-y-label'` option. You may specify a `top label', or title for the plot, by using the ``-L'` option. Doing, for example,

    echo 1 1 2 3 3 1 | graph -T ps -l x -L "A Simple Example" > plot.ps

will produce a plot with a title on top.

The size of the x axis and y axis labels is specified with the ``-f'` option, and the size of the title is specified with the ``--title-font-size'` option. For example,

    echo 1 1 2 3 3 1 | graph -T ps -X "Abscissa" -f 0.1 > plot.ps

will produce a plot in which the font size of the x axis label, and each of the numerical tick labels, is very large (0.1 times the size of the plotting box, i.e., the square within which the plot is drawn).

The font in which the labels specified with the ``-X'`, ``-Y'`, and ``-L'` options are drawn can be specified with the ``-F'` option. For example, ``-F Times-Roman'` will make the labels appear in Times-Roman instead of the default font (which is Helvetica, unless ``-T pnm'`, ``-T gif'`, ``-T pcl'`, ``-T hpgl'` or ``-T tek'` is specified). Font names are case-insensitive, so ``-F times-roman'` will work equally well. The available fonts include 35 Postscript fonts (for all variants of `graph` other than `graph -T pnm`, `graph -T gif`, `graph -T pcl`, `graph -T hpgl` and `graph -T tek`), 45 PCL 5 fonts (for `graph -T ai`, `graph -T pcl` and `graph -T hpgl`), a number of Hewlett--Packard vector fonts (for `graph -T pcl` and `graph -T hpgl`), and 22 Hershey vector fonts. The Hershey fonts include HersheyCyrillic, for Russian, and HersheyEUC, for Japanese. For a discussion of the available fonts, see section Available text fonts. The `plotfont` utility will produce a character map of any available font. See section The `plotfont` Utility.

The format of the labels drawn with the ``-X'`, ``-Y'`, and ``-L'` options may be quite intricate. Subscripts, superscripts, square roots, and switching fonts within a typeface are all allowed. The above examples do not illustrate this, but for details, see section Text string format and escape sequences.

Each of the preceding examples produced a plot containing the default sort of grid (a square box, with ticks and labels drawn along its lower edge and its left edge). There are actually several sorts of grid you may request. The ``-g 0'`, ``-g 1'`, ``-g 2'`, and ``-g 3'` options yield successively fancier grids. What they yield, respectively, is no grid at all, a pair of axes with ticks and labels, a square box with ticks and labels, and a square box with ticks, labels, and grid lines. As you can see, ``-g 2'` is the default. There is also a ``-g 4'` option, which yields a slightly different sort of grid: a pair of axes that cross at the origin. This last sort of grid is useful if the x or y coordinates of the data points you are plotting are both positive and negative.

Go to the first, previous, next, last section, table of contents.