The GNU plotting utilities currently consist of six user-level programs:
graph
, plot
, tek2plot
, spline
, ode
,
and double
. Distributed along with them is GNU libplot
,
a function library for device-independent two-dimensional vector
graphics. This section gives an overview of the plotting utilities and
libplot
.
graph
is a program for plotting two-dimensional scientific data.
It reads one or more data files containing datasets, and outputs a plot.
The plot may be directed to a display device or to a file. Six
different display devices are supported. The corresponding commands are
graph -T X
, graph -T ps
, graph -T fig
, graph
-T hpgl
, graph -T tek
, and graph
.
graph -T X
pops up a window on an X Window System display,
and draws the plot in it. graph -T ps
produces a plot in
encapsulated Postscript format that may be included in another document,
edited with the idraw
drawing editor, or sent directly to a
printer. graph -T fig
produces output that may be displayed and
edited with the xfig
drawing editor. graph -T hpgl
produces a Hewlett--Packard Graphics Language (HP-GL or HP-GL/2) plot
that may be sent to a Hewlett--Packard LaserJet printer or plotter, or
included in another document. graph -T tek
produces output that
may be displayed on a Tektronix 4014 terminal or emulator. graph
without a `-T' option (referred to as `raw graph
') produces
output in a device-independent format, a so-called GNU graphics
metafile. This metafile may be translated into other formats.
graph
can read datasets in both ASCII and binary format, and
datasets in the `table' format produced by the plotting program
gnuplot
. It produces a plot with or without axes and labels.
You may specify labels and ranges for the axes, and you may set the size
and position of the plot on the display device. The labels may contain
subscripts and subscripts, Greek letters, and other special symbols;
there is also support for Cyrillic script (i.e., Russian) and Japanese.
You may specify the type of plotting symbol used for each dataset, and
such parameters as the style and thickness of the line (if any) used
to connect points in a dataset. The plotting of filled regions is
supported, as is the drawing of error bars. graph
provides full
support for multiplotting. With a single invocation of graph
,
you may produce a plot consisting of many sub-plots, either side by side
or inset. Each sub-plot will have its own axes and data.
graph -T X
, graph -T tek
, and raw graph
have a
feature which most plotting programs do not have. They can accept input
from a pipe, and plot data points in real time. For this to occur, the
user must specify ranges for both axes, so that graph
does not
need to wait until the end of the input before determining them.
The plot
program is a so-called plot filter. It can translate
GNU graphics metafiles (produced for example by raw graph
) into
the six supported output formats. The corresponding commands are
plot -T X
, plot -T ps
, plot -T fig
, plot -T
hpgl
, plot -T tek
, and plot
. The plot
program is
useful if you wish to produce output in several different formats while
invoking graph
only once. It is also useful if you wish to
translate files in the traditional `plot(5)' format produced by, e.g.,
the non-GNU versions of graph
provided with some operating
systems. GNU metafile format is compatible with the traditional
`plot(5)' format.
The tek2plot
program can translate from Tektronix format to any
of the abovementioned output formats. The corresponding commands are
tek2plot -T X
, tek2plot -T ps
, tek2plot -T fig
,
tek2plot -T hpgl
, and tek2plot
. tek2plot
is useful
if you have a legacy application that produces drawings in Tektronix
format.
Among the other GNU plotting utilities, spline
does spline
interpolation of data. It normally uses either cubic spline
interpolation or exponential splines in tension, but like graph
it can function as a real-time filter under some circumstances.
ode
provides the ability to integrate an ordinary differential
equation or a system of ordinary differential equations, when provided
with an explicit expression for each equation. It supplements the
plotting program gnuplot
, which can plot functions but not
integrate ordinary differential equations. The final plotting utility,
double
, is a filter for converting, scaling and cutting binary or
ASCII data streams. It is still under development and is not yet
documented.
Distributed along with the plotting utilities is GNU libplot
, the
function library for device-independent two-dimensional vector graphics
on which graph
, plot
, and tek2plot
are based.
libplot
can draw graphics on X Window System displays, and
can generate graphical output in any of five additional formats. This
includes (1) output in encapsulated Postscript format that may be
included in another document, edited with the idraw
drawing
editor, or sent directly to a printer, (2) output that may be
displayed and edited with the xfig
drawing editor, (3) output
in HP-GL or HP-GL/2 format that may be sent to a Hewlett--Packard
LaserJet printer or plotter, (4) output that may be displayed on a
Tektronix 4014 terminal or emulator, and (5) output in the
device-independent GNU graphics metafile format.
libplot
provides the ability to draw such objects as lines, open
and closed polylines, arcs (both circular and elliptic), circles and
ellipses, points, markers, and text strings. The filling of objects
other than points, markers, and text strings is supported (fill color,
as well as pen color, may be set arbitrarily). A wide variety
of line types and marker symbols is supported. The support for drawing
text strings is extensive. The X Window System, Postscript, and
xfig
drivers support the 35 standard Postscript fonts, and the
HP-GL/2 driver supports the 45 standard PCL 5 fonts. All drivers,
including the Tektronix and metafile drivers, support a set of 16
Hershey vector fonts, including HersheyCyrillic. Text strings may
include subscripts and superscripts, and may include characters chosen
from more than one font in a typeface. They may include many
non-alphanumeric characters. The entire collection of 1641 `Hershey
glyphs' digitized c. 1967 by Allen V. Hershey at the
U.S. Naval Surface Weapons Center, which includes many curious symbols,
is built into libplot
. Japanese text strings in the so-called
EUC (Extended Unix Code) format may be also be drawn. Such strings may
include both syllabic characters (Hiragana and Katakana) and ideographic
characters (Kanji). A library of 603 Japanese Kanji digitized by
Dr. Hershey is built into libplot
.
The drawing editors idraw
and xfig
are not distributed
along with the GNU plotting utilities. However, they are free software,
and you may readily obtain them elsewhere (see section Obtaining Auxiliary Software).
graph
Utility
Each invocation of graph
reads one or more datasets from files
named on the command line or from standard input, and prepares a plot.
There are many command-line options for adjusting the visual appearance
of the plot.
See section graph
command-line options, for documentation on all options.
The following sections explain how to use the most frequently used
options, by giving examples.
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 @math{x} @w{and @math{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 @math{x} and @math{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 may 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
xfig
drawing editor, or
graph -T hpgl < ascii_data_file > plot.hpgl
to produce a file plot.hpgl
in the Hewlett--Packard Graphics
Language (HP-GL or HP-GL/2) that you may send to a Hewlett--Packard
LaserJet printer or plotter.
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 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 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 ps
,
graph -T fig
, and graph -T hpgl
. The DISPLAY
and
TERM
environment variables affect the operation of graph -T
X
and graph -T tek
, respectively. There are also several
environment variables that affect the operation of graph -T hpgl
.
For a complete discussion of the effects of the environment on
graph
, see section Environment variables and X Window System resources. The following remarks apply
irrespective of which display device 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 may 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 may 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 indicates. 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 width of the line, whether it is filled or not, by using the `-W' option. For example, `-W 0.01' means that the line should have a width equal to 0.01 times the width 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 devices, 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., @math{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
(@math{x},@math{y},error) rather than pairs @math{(x,y)}. @w{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., @math{x}) values.
By default the limits on the @math{x} and @math{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 @math{x} axis extends from -1
to 3, and the @math{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
@math{y axis} with labeled ticks at -1, 0, 1, and 2,
rather than at the locations that graph
would choose by default.
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 @math{x} axis is logarithmic, but the @math{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 the tick marks at these powers of ten, and no other tick marks, are labeled. If you need more labeled ticks on a logarithmic axis, you should specify a tick spacing manually. For example, `-l x -x 1 9 2' will produce a plot in which the @math{x axis} is logarithmic and extends from 1 to 9. Labeled ticks will be located at each integer multiple of 2, i.e., at 2, 4, 6, and 8.
You may label the @math{x} and @math{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 @math{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 @math{x} axis and @math{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 @math{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 may 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 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 hpgl
and graph -T tek
),
45 PCL 5 fonts (for graph -T hpgl
), and 16 Hershey 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 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 @math{x} @w{or @math{y}} coordinates of the data points you are plotting are both positive and negative.
To alter the linear dimensions of a plot, and also to position it in a different part of your display, you could do something like
graph -T ps -h .3 -w .6 -r .1 -u .1 < ascii_data_file > plot.ps
Here the `-h' and `-w' options specify the height and width of the plotting box, and the `-r' and `-u' options indicate how far up and to the right the lower left corner of the plotting box should be positioned. All dimensions are expressed as fractions of the size of the graphics display, which by convention is a square. By default, the height and width of the plotting box equal 0.6, and the `upward shift' and the `rightward shift' equal 0.2. So the above example will produce a plot that is half as tall as usual. Compared to its usual position, the plot will be shifted slightly downward and to the left.
The `graphics display', within which the plotting box is located, is an
abstraction. For graph -T X
, it is a square window on an X
display. For graph -T tek
, it is a square region occupying the
central part of a Tektronix display. (Tektronix displays are 4/3 times
as wide as they are high.) For graph -T ps
, by default it is
a square region centered on an 8.5in by 11in page (US
letter size), occupying the full width of the page with allowance being
made for margins. For graph -T fig
, by default it is a
square region of the same size, positioned in the upper left corner of
an xfig
display. For graph -T hpgl
, by default it is
a square region of the same size, position and orientation on the page
are controlled by environment variables. The page size used by
graph -T ps
, graph -T fig
, and graph -T hpgl
may be
altered by setting the environment variable PAGESIZE
. For
example, setting it to "a4" would position the graphics display
appropriately on an A4-size page (21cm by 29.7cm).
Changing the width of the plotting box may have unforeseen consequences. A number of command-line options specify sizes or dimensions as fractions of the width of the plotting box. For example, `-S 3 .01' specifies that the plotting symbols for the following dataset should be of type #3, and should have a fractional size equal to 0.01. If the `-w' option is employed to widen or narrow the plot, such dimensions or sizes will scale in tandem. That is presumably the right thing to do, but may be slightly disconcerting.
It is frequently the case that several datasets need to be displayed on the same plot. If so, you may wish to distinguish the points in different datasets by joining them by lines of different types, or by using plotting symbols of different types.
A more complicated example would be the following. You may have a file containing a dataset that is the result of experimental observations, and a file containing closely spaced points that trace out a theoretical curve. The second file is a dataset in its own right. You would presumably plot it with line segments joining successive points, so as to trace out the theoretical curve. But the first dataset, resulting from experiment, would be plotted without such line segments. In fact, a plotting symbol would be plotted at each of its points.
These examples, and others like them, led us to define a set of seven attributes which define the way in which a dataset should be plotted. These attributes, which may be set by command-line options, are the following.
Color/monochrome (a choice of one or the other) is the simplest. This choice is toggled with the `-C' option. The `linemode' (i.e., line style) specifies how the line segments joining successive points should be drawn; it is specified with the `-m' option. Linemode #0 means no linemode at all, for example. `Linewidth' is self-explanatory; it is specified with the `-W' option. `Symbol type' and `symbol size', which are specified with the `-S' option, specify the symbol plotted at each point of the dataset. `Symbol font name' refers to the font from which plotting symbols #32 and above, which are taken to be characters rather than geometric symbols, are selected. It is set with the `--symbol-font-name' option, and is relevant only if `-S' is used to request such special plotting symbols. Finally, the polygonal line joining the points in a dataset may be filled, to create a filled or shaded polygon. The `fill fraction' is set with the `-q' option. A negative fill fraction means no fill, or transparent; zero means white, and 1.0 means solid, or fully colored.
The preceding seven attributes refer to the way in which datasets are plotted. Datasets may also differ from one another in the way in which they are read from files. The dataset(s) in a file may or may not contain error bars, for example. If a file contains data with error bars, the `-I e' option should occur on the command line before the file name. (The `-I' option specifies the input format for the following files.)
The following illustrates how datasets in three different input files could be plotted simultaneously.
graph -T ps -m 0 -S 3 file_1 -C -m 3 file_2 -C -W 0.02 file_3 > output.ps
The dataset in file_1
will be plotted in linemode #0, so
successive points will not be joined by lines. But symbol #3 (an
asterisk) will be plotted at each point. The dataset in file_2
will be plotted in color, and linemode #3 will be used. In color
plotting, linemode #3 is interpreted as a solid blue line. The second
`-C' on the command line turns off color for file_3
. The
points in the third dataset will be joined by a black line of width
0.02, as a fraction of the width of the graphics display.
The above command line could be made even more complicated by specifying additional options (e.g., `-q' or `-I') before each file. In fact the command line could also include such standard options as `-x' or `-y', which specify the range of each axis. Such options, which refer to the plot as a whole rather than to individual datasets, should appear before the first file name. For example, you could do
graph -T ps -x 0 1 0.5 -m 0 -S 3 file_1 -C -m 3 file_2 > output.ps
Note that it is possible to include the special file name `-',
which refers to standard input, on the command line. So you may produce
a plot in part from files, and in part from input that is piped to
graph
from another program.
Each input file may include more than one dataset. If so, the command line options preceding a file on the command line will take effect for all datasets in that file. There are two exceptions to this. By default, the linemode is incremented (`bumped') from one dataset to the next. This feature is usually quite convenient. For example, if you do
graph -T ps -m 3 file_1 > output.ps
the first dataset in file_1
will appear in linemode #3, the
second in linemode #4, etc. In fact if you do
graph -T ps file_1 file_2 ... > output.ps
without specifying linemode explicitly, the successive datasets read from the files on the command line will appear in linemode #1, linemode #2, .... If you do not like this feature, you may turn it off, or in general toggle it, by using the `-B' option.
You may also control manually the linemode and symbol type used for the datasets within any file. You would do this by including directives in the file itself, rather than on the command line. For example, if the line
#m=-5,S=10
appeared in an ASCII-format input file, it would be interpreted as a
directive to switch to linemode #-5 and symbol type #10 for the
following dataset. Future releases of graph
may provide the
ability to set each of the seven dataset attributes in this way.
It is occasionally useful to display several plots at once on a single page, or on a single graphics display. We call such a composite plot a multiplot. One common sort of multiplot is a small plot inset into a larger one. Another sort is two or more plots side by side.
graph
can draw multiplots consisting of an arbitrarily large
number of sub-plots. When multiplotting, graph
draws each
sub-plot in its own `virtual display'. When a conventional plot is
drawn, the virtual display is the same as the physical display. But
when a multiplot is drawn, the virtual display may be any smaller square
region.
The following example illustrates the idea. For the present purposes, the physical display is a square with lower left corner (0.0,0.0) and upper right corner (1.0,1.0).
graph -T ps data_file_1 --reposition 0.35 0.35 0.3 data_file_2
Here data_file_1
is plotted in the usual way. The virtual
display is then shrunk to a square of size 0.3, with lower left corner
(0.35,0.35). A plot is then prepared from data_file_2
, and
drawn. This plot, as you can see, will be a much smaller plot that is
inset into the first plot.
By convention, before each sub-plot of a multiplot other than the first is drawn, a `blankout region' surrounding its plotting box is erased. (That is, it is filled with white.) This erasure prevents the sub-plots from overlapping and producing a messy result. By default, the blankout region is a rectangular region 30% larger in each dimension than the plotting box for the sub-plot. This is appropriate if the sub-plot is a small one that is inset into the first sub-plot. It may not be appropriate, however, if you are preparing a multiplot in which several sub-plots appear side by side. You may use the `--blankout' option to adjust this parameter. For example, specifying `--blankout 1.0' will make the blankout region for a sub-plot coincide with its plotting box. Specifying `--blankout 0.0' will prevent any blanking out from occurring. The blankout parameter may differ from sub-plot to sub-plot.
It should be emphasized that every sub-plot in a multiplot is a plot in
its own right. All the usual options (`-m', `-S', `-x',
`-y', etc.) may be applied to each sub-plot separately. The
options for a sub-plot should occur on the graph
command line
immediately after the `--reposition' option that applies to it.
Each sub-plot may be prepared from more than a single dataset, also.
The names of the data files for each subplot should occur on the command
line before the following `--reposition' option, if any.
By default, graph
reads datasets in ASCII format. But it can
also read datasets in any of three binary formats (single precision
floating point, double precision floating point, and integer).
These three input formats are specified by the `-I d', `-I f',
and `-I i' options, respectively.
There are two advantages to using binary data: 1) graph
runs
significantly faster because the computational overhead for converting
data from ASCII to binary is eliminated, and 2) the input files may
be significantly smaller. If you have very large datasets, using
binary format may reduce storage and runtime costs.
For example, you may create a single precision binary dataset as output from a C language program:
#include <stdio.h> void write_point (float x, float y) { fwrite(&x, sizeof (float), 1, stdout); fwrite(&y, sizeof (float), 1, stdout); }
You may plot data written this way by doing:
graph -T ps -I f < binary_data_file > plot.ps
If you are reading datasets from more than one file, it is not required that the files be in the same format. For example,
graph -T ps -I f binary_data_file -I a ascii_data_file > plot.ps
will read binary_data_file
in `f' (binary single precision)
format, and ascii_data_file
in `a' (normal ASCII) format.
There is currently no support for reading and plotting binary data with
error bars. If you have data with error bars, you should supply the data
to graph
in ASCII, and use the `-I e' option.
graph
can also read data files in the ASCII `table' format
produced by the gnuplot
plotting program. For this, you should
use the `-I g' option. Such a data file may consist of more than
one dataset.
To sum up: there are six supported data formats, `a' (normal
ASCII), `e' (ASCII with error bars), `g' (the ASCII `table'
format produced by gnuplot
), `f' (binary single precision),
`d' (binary double precision), and `i' (binary integer).
Input files may be in any of these six formats.
graph
command-line options
The command-line options to graph
are listed in the following
sections. Each option that takes an argument is followed, in
parentheses, by the type and default value of the argument. There are
five sorts of option.
graph
, i.e., relevant only if no
display device is specified with the `-T' option. (section Raw graph
options.)
The following options affect an entire plot. They should normally occur at most once, and should appear on the command line before the first filename. If a multiplot is being drawn, they may (with the exception of the `-T' option) occur more than once. If so, the second and later occurrences should be placed on the command line immediately after each `--reposition x y' option.
idraw
-editable Postscript, the format used by the xfig
drawing editor, the Hewlett--Packard Graphics Language, Tektronix
format, and device-independent GNU metafile format.
graph -T hpgl
and
graph -T tek
, for which "HersheySerif" is the default.) Set the
font used for the axis and tick labels, and for the plot title (if
any), to be font_name. The choice of font for the plot title may
be overridden with the `--title-font-name' option (see below).
Font names are case-insensitive. For a list of available fonts, see
section Available text fonts. If the specified font is not available, the default
font will be used.
graph
not erase the
display device before it begins to plot. This is relevant only to
graph -T tek
and raw graph
. It may be employed to
perform a crude sort of multiplotting.
graph
is to act as a real-time filter.
graph
is to act as a real-time filter.
libplot
graphics library should be used. This
value is device-dependent. The interpretation of zero line width is
also device-dependent (on some devices, a zero-width line is the
thinnest line that can be drawn; on others, a zero-width line is
invisible).
graph -T tek
does not support drawing lines with other than a
default width, and graph -T hpgl
does not support doing so if
the environment variable HPGL_VERSION
is set to a value less than
"2" (the default).
idraw
.
MAX_LINE_LENGTH
may
also be used to specify the maximum line length. This option has no
effect in graph -T tek
or raw graph
, since they draw
polylines in real time.
graph -T ps
,
graph -T fig
, and graph -T hpgl
. "letter" means an 8.5in
by 11in page. Any ISO page size in the range "a0"..."a4" or
ANSI page size in the range "a"..."e" may be specified ("letter" is
an alias for "a" and "tabloid" is an alias for "b"). "legal"
and "ledger" are recognized page sizes also. The environment variable
PAGESIZE
may equally well be used to specify the page size.
For graph -T ps
, the graphics display within which the plot is drawn
will be a square region centered on the specified page and occupying its
full width. For graph -T fig
, the graphics display will be a square
region located in the upper left corner of an xfig
display, with
width equal to the width of the specified page. graph -T hpgl
, fine
control over the positioning of the graphics display on the page may be
accomplished by setting certain environment variables (see section Environment variables and X Window System resources).
graph -T hpgl
. It facilitates switching between portrait and
landscape orientations. Recognized values for angle are 0, 90,
180, and 270. "no" and "yes" are equivalent to 0 and 90,
respectively. The environment variable ROTATE
may equally well
be used to specify the rotation angle.
graph -T hpgl
and
graph -T tek
, for which "HersheySerif" is the default.) Set the
font used for the plot title (`top label') to be font_name.
Normally the font used for the plot title is the same as that used for
labelling the axes and the ticks along the axes, as specified by the
`-F' option. But the `--title-font-name' option may be used
to override this. Font names are case-insensitive; for a list of
available fonts, see section Available text fonts. If the font is not
available, the default font will be used.
The following options affect the way in which individual datasets are read from files, and drawn as part of a plot. They should appear on the command line before the file containing the datasets whose reading or rendering they will affect. They may appear more than once on a command line, if more than one file is to be read.
The following three options affect the way in which datasets are read from files.
gnuplot
plotting program.
The following options affect the way in which individual datasets are drawn as part of a plot. These options set the six `attributes' (symbol type, symbol font, linemode, line width, fill fraction, and color/monochrome) that each dataset has.
libplot
graphics
library. See section Available marker symbols. Symbol numbers greater than or equal
to 32 are interpreted as characters to be selected from a symbol font,
which may be set with the `--symbol-font-name' option (see below).
libplot
graphics
library should be used. This value is device-dependent. The
interpretation of zero line width is also device-dependent (on some
devices, a zero-width line is the thinnest line that can be drawn; on
others, a zero-width line is invisible).
graph -T tek
does not support drawing lines with other than a
default width, and graph -T hpgl
does not support doing so if
the environment variable HPGL_VERSION
is set to a value less than
"2" (the default).
graph -T tek
, and it has no
effect in graph -T hpgl
if the environment variable
HPGL_VERSION
is set to "1".
-T tek
is specified, in which case it is "HersheySerif".) Set the symbol font,
from which plotting symbols numbered 32 and higher are selected, to be
symbol_font_name. Font names are case-insensitive. For a list of
available fonts, see section Available text fonts.
The following options are used for multiplotting (placing several plots on a display, or a page, at once).
graph -T tek
cannot clear regions, and graph -T hpgl
cannot clear them unless
the environment variable HPGL_VERSION
is set to "2" (the default)
and the environment variable HPGL_OPAQUE_MODE
is set to "yes".
graph
options
The following options are relevant only to raw graph
, i.e., are
relevant only if no display device is specified with the `-T'
option. In this case graph
outputs a graphics metafile. They
should appear on the command line before any filenames, since they
affect the output of the plot (or multiplot) as a whole.
The following options request information.
graph -T X
, graph -T ps
, and graph -T fig
each
support the 35 standard Postscript fonts. graph -T hpgl
supports
the 45 standard PCL 5 fonts. All four, together with graph -T
tek
, support a set of 16 Hershey vector fonts. Raw graph
in
principle supports any font, since its output must be translated to
other formats with plot
.
graph
and the plotting utilities
package, and exit.
The behavior of graph
is affected by several environment
variables and X Window System resources. We have already mentioned
the environment variables PAGESIZE
, ROTATE
, and
MAX_LINE_LENGTH
. They simply serve as backups for the options
`--page-size', `--rotate', and `--max-line-length'. The
remaining environment variables are specific to individual display
devices. They control device driver parameters.
graph -T X
, which pops up a window on an X Window System display
and draws graphics in it, checks the DISPLAY
environment
variable. The value of this variable determines the display on which
the window will be popped up. graph -T X
also looks at the X
resource Xplot.geometry
. It will use the value of this
resource, which may be set by the user, as the size of the window in
terms of pixels. The default value is "570x570".
graph -T hpgl
, which produces Hewlett--Packard Graphics Language
output, is affected by several environment variables. The most
important is HPGL_VERSION
, which may be set to "1", "1.5", or
"2" (the default). "1" means that the output should be generic
HP-GL, "1.5" means that the output should be suitable for the
HP7550A pen plotter (HP-GL with some HP-GL/2 extensions), and "2" means
that the output should be modern HP-GL/2. By default, graph
-T hpgl
will draw with a fixed set of pens. Which pens are present may
be specified by setting the HPGL_PENS
environment variable. If
HPGL_VERSION
is "1" or "1.5", the default value of
HPGL_PENS
is "1=black"; if HPGL_VERSION
is "2", the
default value of HPGL_PENS
is
"1=black:2=red:3=green:4=yellow:5=blue:6=magenta:7=cyan". The format
should be self-explanatory. HPGL_PENS
may specify a color for
any pen in the range #1...#31. For information on what color names
are recognized, see section Specifying Colors by Name. Pen #1 must always be
present, though it need not be black. Any other pen in the range
#1...#31 may be omitted.
If HPGL_VERSION
is "2" then graph -T hpgl
will be affected by
two other environment variables. If the value of
HPGL_ASSIGN_COLORS
is "yes", then graph -T hpgl
will not be
restricted to the palette specified in HPGL_PENS
: it will
assign colors to "logical pens" in the range #1...#31, as
needed. Also, if HPGL_OPAQUE_MODE
is set equal to "yes" then
pen #0 will be used as an opaque white pen, permitting the drawing
of white lines and the filling of objects with opaque white. Not all
HP-GL/2 devices allow the assignment of colors to logical pens, or the
use of pen #0 as an opaque white pen. In particular, HP-GL/2 pen
plotters do not. So these two environment variables should be
used with caution.
The position of the graph -T hpgl
graphics display on the page may
be adjusted by setting the HPGL_XOFFSET
and HPGL_YOFFSET
environment variables, which may be specified in centimeters,
millimeters, or inches. For example, an offset could be specified as
"2cm" or "1.2in". Also, the display may be rotated 90 degrees on
the page by using the `--rotate 90' option, or setting the
ROTATE
environment variable to "yes".
graph -T tek
, which produces output for a Tektronix terminal or
emulator, checks the TERM
environment variable. If the value
of TERM
is xterm
, xterms
, or kterm
, it
is taken as a sign that the current application is running in an X
Window System VT100 terminal emulator: an xterm
. Before
drawing graphics, graph -T tek
will emit an escape sequence that
causes the terminal emulator's auxiliary Tektronix window, which is
normally hidden, to pop up. After the graphics are drawn, an escape
sequence that returns control to the original VT100 window will be
emitted. The Tektronix window will remain on the screen.
If the value of TERM
is kermit
, ansi.sys
,
ansissys
, ansi.sysk
, or ansisysk
, it is taken
as a sign that the current application is running in the VT100 terminal
emulator provided by the DOS version of kermit
. Before drawing
graphics, graph -T tek
will emit an escape sequence that switches
the terminal emulator to Tektronix mode. Also, some of the Tektronix
control codes output by graph -T tek
will be
kermit
-specific. There will be a limited amount of color
support, which is not normally the case (the 16 ansi.sys
colors
will be supported). After drawing graphics, graph -T tek
will emit
an escape sequence that returns the emulator to VT100 mode. The key
sequence `ALT minus' may be employed manually within kermit
to switch between the two modes.
plot
Utilityplot
The GNU plot filter plot
translates GNU graphics metafiles to
other formats. The `-T' option is used to specify the type of
display device.
Graphics metafiles are produced by the graph
utility if no
`-T' option is specified on its command line, and may also be
produced by the libplot
library. The metafile format is a
device-independent format for storage of graphic data. By default, it
is a binary rather than an human-readable format (see section The Graphics Metafile Format).
plot
, like the metafile format itself, is useful if you wish to
preserve a plot that is to be displayed or edited on more than one type
of display device. The following illustrate how this is done.
To produce a plot of data arranged as alternating @math{x} and @math{y}
coordinates in an ASCII file, you may use raw graph
as follows:
graph < ascii_data_file > test.plot
The file `test.plot' will be a GNU graphics metafile. Similarly, to create a plot consisting of a simple figure, you may do:
echo 0 0 1 1 2 0 | spline | graph > test.plot
To display any such plot on an X Window System display, you would do
plot -T X < test.plot
To print the plot on a Postscript printer, you would do something like
plot -T ps < test.plot | lpr
To edit it with the idraw drawing editor, you would do
plot -T ps < test.plot > test.ps idraw test.ps
And to produce a plot that may be edited with the xfig
drawing
editor, you would do
plot -T fig < test.plot > test.fig xfig test.fig
plot
may behave differently depending on the environment in which
it is invoked. In particular, plot -T ps
, plot -T fig
,
and plot -T hpgl
are affected by the environment variable
PAGESIZE
. plot -T X
and plot -T tek
are affected
by the environment variables DISPLAY
and TERM
,
respectively. There are also several environment variables that affect
the operation of plot -T hpgl
. For a complete discussion of the
effects of the environment on plot
, see section Environment variables and X Window System resources.
plot
command-line options
The command-line options to GNU plot
are listed below. There are
four sorts of option:
plot
, i.e., relevant only if no
display device is specified with the `-T' option.
Each option that takes an argument is followed, in parentheses, by the type and default value of the argument.
Note that input file names may be specified anywhere on the command line. Only the options that precede a file name will take effect for that file. If no file names are specified, or the name `-' is specified, the standard input is read.
The following options set the values of drawing parameters.
idraw
-editable Postscript, the format used by the xfig
drawing editor, the Hewlett--Packard Graphics Language, Tektronix
format, and device-independent GNU metafile format.
MAX_LINE_LENGTH
may also
be used to specify the maximum line length. This option has no effect
in plot -T tek
or raw plot
, since they draw polylines in
real time.
plot -T ps
,
plot -T fig
, and plot -T hpgl
. "letter" means an 8.5in by
11in page. Any ISO page size in the range "a0"..."a4" or ANSI
page size in the range "a"..."e" may be specified ("letter" is an
alias for "a" and "tabloid" is an alias for "b"). "legal" and
"ledger" are recognized page sizes also. The environment variable
PAGESIZE
may equally well be used to specify the page size.
For plot -T ps
, the graphics display within which the plot is drawn
will be a square region centered on the specified page and occupying its
full width. For plot -T fig
, the graphics display will be a square
region located in the upper left corner of an xfig
display, with
width equal to the width of the specified page. For plot -T hpgl
,
fine control over the positioning of the graphics display on the page
may be accomplished by setting certain environment variables
(see section Environment variables and X Window System resources).
plot -T hpgl
. It facilitates switching between portrait and
landscape orientations. Recognized values for angle are 0, 90,
180, and 270. "no" and "yes" are equivalent to 0 and 90,
respectively. The environment variable ROTATE
may equally well
be used to specify the rotation angle.
The following options set the initial values of additional drawing parameters. All of these may be overridden by directives in the metafile itself. In fact, these options are useful mostly for plotting old metafiles in the pre-GNU `plot(5)' format, which did not include such directives.
plot -T hpgl
and
plot -T tek
, for which "HersheySerif" is the default.) Set the font
initially used for text (i.e., for `labels') to font_name. Font
names are case-insensitive. For a list of available fonts, see
section Available text fonts. If the specified font is not available, the default
font will be used.
libplot
graphics
library should be used. This value is device-dependent. The
interpretation of zero line width is also device-dependent (on some
devices, a zero-width line is the thinnest line that can be drawn; on
others, a zero-width line is invisible).
plot -T tek
does not support drawing lines with other than a default
width, and plot -T hpgl
does not support doing so if the
environment variable HPGL_VERSION
is set to a value less than "2"
(the default).
The following option is relevant only to raw plot
, i.e., relevant
only if no display device is specified with the `-T' option. In
this case plot
outputs a graphics metafile.
plot
will automatically determine which type of GNU metafile
format the input is in. There are two types: binary (the default)
and portable (human-readable). The binary format is machine-dependent.
See section The Graphics Metafile Format.
For compatibility with older software, the reading of input files in the pre-GNU `plot(5)' metafile format is also supported. This is a binary format, with each integer argument represented as exactly two bytes. The order of the two bytes is machine dependent. You may specify that the input is in plot(5) format rather than the ordinary GNU metafile format by using either the `-h' option ("high byte first") or the `-l' option ("low byte first").
The following options request information.
plot
-T X
, plot -T ps
, and plot -T fig
each support the 35
standard Postscript fonts. plot -T hpgl
supports the 45 standard
PCL 5 fonts. All four, together with plot -T hpgl
and
plot -T tek
, support a set of 16 Hershey vector fonts. Raw
plot
in principle supports any font, since its output must be
translated to other formats by a later invocation of plot
.
plot
and the plotting utilities
package, and exit.
The behavior of plot
is affected by several environment variables
and X Window System resources. We have already mentioned the
environment variables PAGESIZE
, ROTATE
, and
MAX_LINE_LENGTH
. They simply serve as backups for the options
`--page-size', `--rotate', and `--max-line-length'. The
remaining environment variables are specific to individual display
devices. They control device driver parameters.
plot -T X
, which pops up a window on an X Window System display
and draws graphics in it, checks the DISPLAY
environment
variable. The value of this variable determines the display on which
the window will be popped up. plot -T X
also looks at the X
resource Xplot.geometry
. It will use the value of this
resource, which may be set by the user, as the size of the window in
terms of pixels. The default value is "570x570".
plot -T hpgl
, which produces Hewlett--Packard Graphics Language
output, is affected by several environment variables. The most
important is HPGL_VERSION
, which may be set to "1", "1.5", or
"2" (the default). "1" means that the output should be generic
HP-GL, "1.5" means that the output should be suitable for the
HP7550A pen plotter (HP-GL with some HP-GL/2 extensions), and "2" means
that the output should be modern HP-GL/2. By default, plot -T
hpgl
will draw with a fixed set of pens. Which pens are present may be
specified by setting the HPGL_PENS
environment variable. If
HPGL_VERSION
is "1" or "1.5", the default value of
HPGL_PENS
is "1=black"; if HPGL_VERSION
is "2", the
default value of HPGL_PENS
is
"1=black:2=red:3=green:4=yellow:5=blue:6=magenta:7=cyan". The format
should be self-explanatory. HPGL_PENS
may specify a color for
any pen in the range #1...#31. For information on what color names
are recognized, see section Specifying Colors by Name. Pen #1 must always be
present, though it need not be black. Any other pen in the range
#1...#31 may be omitted.
If HPGL_VERSION
is "2" then plot -T hpgl
will be affected by
two other environment variables. If the value of
HPGL_ASSIGN_COLORS
is "yes", then plot -T hpgl
will not be
restricted to the palette specified in HPGL_PENS
: it will
assign colors to "logical pens" in the range #1...#31, as
needed. Also, if HPGL_OPAQUE_MODE
is set equal to "yes" then
pen #0 will be used as an opaque white pen, permitting the drawing
of white lines and the filling of objects with opaque white. Not all
HP-GL/2 devices allow the assignment of colors to logical pens, or the
use of pen #0 as an opaque white pen. In particular, HP-GL/2 pen
plotters do not. So these two environment variables should be
used with caution.
The position of the plot -T hpgl
graphics display on the page may be
adjusted by setting the HPGL_XOFFSET
and HPGL_YOFFSET
environment variables, which may be specified in centimeters,
millimeters, or inches. For example, an offset could be specified as
"2cm" or "1.2in". Also, the display may be rotated 90 degrees on
the page by using the `--rotate 90' option, or setting the
ROTATE
environment variable to "yes".
plot -T tek
, which produces output for a Tektronix terminal or
emulator, checks the TERM
environment variable. If the value
of TERM
is xterm
, xterms
, or kterm
, it
is taken as a sign that the current application is running in an X
Window System VT100 terminal emulator: an xterm
. Before
drawing graphics, plot -T tek
will emit an escape sequence that
causes the terminal emulator's auxiliary Tektronix window, which is
normally hidden, to pop up. After the graphics are drawn, an escape
sequence that returns control to the original VT100 window will be
emitted. The Tektronix window will remain on the screen.
If the value of TERM
is kermit
, ansi.sys
,
ansissys
, ansi.sysk
, or ansisysk
, it is taken
as a sign that the current application is running in the VT100 terminal
emulator provided by the DOS version of kermit
. Before drawing
graphics, plot -T tek
will emit an escape sequence that switches
the terminal emulator to Tektronix mode. Also, some of the Tektronix
control codes output by plot -T tek
will be
kermit
-specific. There will be a limited amount of color
support, which is not normally the case (the 16 ansi.sys
colors
will be supported). After drawing graphics, plot -T tek
will
emit an escape sequence that returns the emulator to VT100 mode. The
key sequence `ALT minus' may be employed manually within
kermit
to switch between the two modes.
tek2plot
Utilitytek2plot
The GNU Tektronix translator tek2plot
translates Tektronix
graphics format, which is produced by many legacy applications, to other
formats. The supported output formats are the same six formats that are
supported by the GNU graph
and plot
utilities.
tek2plot
will take input from a file specified on the command
line or from standard input, just as the plot filter plot
does.
The invocation of tek2plot
is similar to the invocation of
plot
. See section The plot
Utility.
Tektronix graphics format is defined as a noninteractive version of the
graphics format understood by Tektronix 4010/4014 terminals, as
documented in the 4014 Service Manual, Tektronix Inc., 1974
(Tektronix Part #070-1648-00). tek2plot
does not support
interactive features such as GIN mode and status enquiry. However, it
does support a few features of popular Tektronix emulators, such as the
color extensions supported by the Tektronix emulator contained in the
MS-DOS version of kermit
.
tek2plot
command-line options
The command-line options to the Tektronix translator tek2plot
are
listed below. There are three sorts of option:
tek2plot
, i.e., relevant only if no
display is specified with the `-T' option.
Each option that takes an argument is followed, in parentheses, by the type and default value of the argument.
Note that input file names may be specified anywhere on the command line. Only the options that precede a file name will take effect for that file. If no file names are specified, or the name `-' is specified, the standard input is read.
The following are general options.
idraw
-editable Postscript, the format used by the xfig
drawing editor, the Hewlett--Packard Graphics Language, Tektronix
format, and device-independent GNU metafile format.
tek2plot -T X
, tek2plot -T tek
,
and tek2plot -T meta
display these pages in succession,
finally displaying the last page. By default, the other variants of
tek2plot
display only the last page. This option may be used to
override the default behavior and select a particular page for display.
Most Tektronix files consist of either one page (page #0) or two pages
(an empty page #0, and page #1). Tektronix files produced
by the GNU plotting utilities (e.g., by graph -T tek
) are
normally of the latter sort.
tek2plot -T hpgl
, for which
"HersheySerif" is the default.) Set the font initially used for text to
font_name. Font names are case-insensitive. For a list of
available fonts, see section Available text fonts. If a font outside the
Courier family is chosen, the `--position-chars' option (see below)
should probably be used. For a list of available fonts, see section Available text fonts. If the specified font is not available, the default font will
be used.
libplot
graphics
library should be used. This value is device-dependent. The
interpretation of zero line width is also device-dependent (on some
devices, a zero-width line is the thinnest line that can be drawn; on
others, a zero-width line is invisible).
tek2plot -T hpgl
does not support drawing lines with other than a
default width if the environment variable HPGL_VERSION
is set to
a value less than "2" (the default).
MAX_LINE_LENGTH
may also
be used to specify the maximum line length. This option has no effect
in raw tek2plot
, which has no buffer limitations.
tek2plot -T ps
,
tek2plot -T fig
, and tek2plot -T hpgl
. "letter" means an
8.5in by 11in page. Any ISO page size in the range
"a0"..."a4" or ANSI page size in the range "a"..."e" may be
specified ("letter" is an alias for "a" and "tabloid" is an alias
for "b"). "legal" and "ledger" are recognized page sizes also. The
environment variable PAGESIZE
may equally well be used to specify
the page size.
For tek2plot -T ps
, the graphics display within which the plot is
drawn will be a square region centered on the specified page and
occupying its full width. For tek2plot -T fig
, the graphics
display will be a square region located in the upper left corner of an
xfig
display, with width equal to the width of the specified
page. For tek2plot -T hpgl
, fine control over the positioning of
the graphics display on the page may be accomplished by setting certain
environment variables (see section Environment variables and X Window System resources).
xfig
or
idraw
.
tek2plot -T hpgl
. It facilitates switching between portrait and
landscape orientations. Recognized values for angle are 0, 90,
180, and 270. "no" and "yes" are equivalent to 0 and 90,
respectively. The environment variable ROTATE
may equally well
be used to specify the rotation angle.
tek2plot -T X
. The
four relevant bitmap fonts are distributed as part of the plotting
utilities package under the names tekfont0
...tekfont3
.
They may readily be installed on any modern X Windows server. For
this option to work properly, you must also select a window size of
"1024x1024" pixels, by setting the Xplot.geometry
resource.
See section Environment variables and X Window System resources. The reason for this restriction is that
bitmap fonts, unlike the scalable fonts that the plotting utilities
normally use, may not be rescaled.
The following option is relevant only to raw tek2plot
, i.e.,
relevant only if no display device is specified with the `-T'
option. In this case tek2plot
outputs a graphics metafile.
The following options request information.
tek2plot -T X
, tek2plot -T ps
, and tek2plot -T fig
each support the 35 standard Postscript fonts. tek2plot -T hpgl
supports the 45 standard PCL 5 fonts. All four, together with
tek2plot -T hpgl
, support a set of 16 Hershey vector fonts. Raw
tek2plot
in principle supports any font, since its output must be
translated to other formats with plot
.
tek2plot
and the plotting utilities
package, and exit.
The behavior of tek2plot
is affected by several environment
variables and X Window System resources, which are the same as those
that affect graph
and plot
. For convenience, we list them
here.
We have already mentioned the environment variables PAGESIZE
,
ROTATE
, and MAX_LINE_LENGTH
. They simply serve as backups
for the options `--page-size', `--rotate', and
`--max-line-length'. The remaining environment variables are
specific to individual display devices. They control device driver
parameters.
tek2plot -T X
, which pops up a window on an X Window System
display and draws graphics in it, checks the DISPLAY
environment variable. The value of this variable determines the display
on which the window will be popped up. tek2plot -T X
also
looks at the X resource Xplot.geometry
. It will use the
value of this resource, which may be set by the user, as the size of the
window in terms of pixels. The default value is "570x570".
tek2plot -T hpgl
, which produces Hewlett--Packard Graphics
Language output, is affected by several environment variables. The most
important is HPGL_VERSION
, which may be set to "1", "1.5", or
"2" (the default). "1" means that the output should be generic
HP-GL, "1.5" means that the output should be suitable for the
HP7550A pen plotter (HP-GL with some HP-GL/2 extensions), and "2" means
that the output should be modern HP-GL/2. By default,
tek2plot -T hpgl
will draw with a fixed set of pens. Which pens
are present may be specified by setting the HPGL_PENS
environment
variable. If HPGL_VERSION
is "1" or "1.5", the default value
of HPGL_PENS
is "1=black"; if HPGL_VERSION
is "2", the
default value of HPGL_PENS
is
"1=black:2=red:3=green:4=yellow:5=blue:6=magenta:7=cyan". The format
should be self-explanatory. HPGL_PENS
may specify a color for
any pen in the range #1...#31. For information on what color names
are recognized, see section Specifying Colors by Name. Pen #1 must always be
present, though it need not be black. Any other pen in the range
#1...#31 may be omitted.
If HPGL_VERSION
is "2" then tek2plot -T hpgl
will be
affected by two other environment variables. If the value of
HPGL_ASSIGN_COLORS
is "yes", then tek2plot -T hpgl
will
not be restricted to the palette specified in HPGL_PENS
: it
will assign colors to "logical pens" in the range #1...#31, as
needed. Also, if HPGL_OPAQUE_MODE
is set equal to "yes" then
pen #0 will be used as an opaque white pen, permitting the drawing
of white lines and the filling of objects with opaque white. Not all
HP-GL/2 devices allow the assignment of colors to logical pens, or the
use of pen #0 as an opaque white pen. In particular, HP-GL/2 pen
plotters do not. So these two environment variables should be
used with caution.
The position of the tek2plot -T hpgl
graphics display on the page
may be adjusted by setting the HPGL_XOFFSET
and
HPGL_YOFFSET
environment variables, which may be specified in
centimeters, millimeters, or inches. For example, an offset could be
specified as "2cm" or "1.2in". Also, the display may be rotated 90
degrees on the page by using the `--rotate 90' option, or setting
the ROTATE
environment variable to "yes".
spline
Utilityspline
GNU spline
is a program for interpolating between the data points
in one or more datasets. Each dataset would consist of values for an
independent variable and a single dependent variable. When discussing
interpolation, we call these variables `@math{t}' and `@math{x}',
respectively. The simplest case is when there is only a single dataset,
in ASCII format. For example, the input file could contain the lines
0.0 0.0 1.0 1.0 2.0 0.0
which are the coordinates @math{(t,x)} of the data points (0,0), (1,1), and (2,0). Data points do not need to be on different lines, nor do the @math{t} @w{and @math{x}} 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. Also, the @math{t} coordinates should be monotonically increasing: the dataset must have an interpretation as a function.
You would construct a curve (an `interpolating spline') passing through the points in such a dataset by doing
spline input_file > output_file
To produce a Postscript plot of the spline with the graph
utility, you would do
spline input_file | graph -T ps > output.ps
To display a spline on an X Window System display, you could do
echo 0 0 1 1 2 0 | spline | graph -T X
Notice that the last example avoids the use of the input file
altogether. spline
will read from standard input if no files are
specified on the command line, or if the special name name `-'
is specified.
What exactly does spline
do? First, it fits a curve through the
points in the dataset. Then it splits the interval over which the
independent variable @math{t} ranges into 100 sub-intervals, and
computes the @math{x values} at each of the 101 subdivision points.
It then outputs each of the pairs @math{(t, x)}. These are the
coordinates of 101 points that lie along a curve that interpolates
between the points in the dataset. If there is more than one dataset in
the input (separated by blank lines), each dataset is interpolated
separately.
You may use the `-n' option to replace `100' by any other integer. You may also use the `-t' option to specify an interpolation interval that differs from the default (the interval over which the independent variable ranges). For example, the command
echo 0 0 1 1 2 0 | spline -n 20 -t 1.0 1.5 > output_file
will produce a dataset consisting of 21 (rather than 101) data points, with @math{t values} spaced regularly between 1.0 and 1.5 (rather than between 0.0 and 2.0). The data points will lie along a curve passing through (0,0), (1,1), and (2,0). This curve will be a parabola.
In general, the interpolating curve will be a piecewise cubic spline. That is, between each pair of adjacent `nodes' (points in the input dataset), @math{x} will be a cubic function @w{of @math{t}}. This function will differ, depending on which pair of nodes @math{t lies} between. At each node, both the slope and curvature of the cubic pieces to either side will match. In mathematical terms, the interpolating curve will be twice continuously differentiable.
spline
supports `adding tension' to the interpolating curve. A
nonzero value for the tension may be specified with the `-T'
option. For example, a spline under considerable tension may be
computed and displayed by doing
echo 0 0 1 0 2 0 | spline -T 10 | graph -T X
As the tension parameter is increased to positive infinity, the spline will converge to a polygonal line. You are supposed to think of the spline as being drawn taut. Actually, tension may be negative as well as positive. A spline with negative tension will tend to bow outward, in fact to oscillate sinusoidally. But as the tension decreases to negative infinity, the spline, though oscillatory, will again converge to a polygonal line.
If the tension is positive, its reciprocal will be the maximum range of the independent variable @math{t} over which the spline will `like to curve'. Increasing the tension far above zero will accordingly force the spline to consist of short curved sections, centered on the data points, and sections that are almost straight. It follows that tension is a `dimensionful' quantity. If the tension is nonzero, then when the values of the independent variable are multiplied by some common positive factor, the tension should be divided by the same factor to obtain a scaled version of the original spline. If the tension is zero (the default, or cubic spline case), then the computation of the spline will be unaffected by linear scaling of the data.
In mathematical terms, a spline under tension will satisfy the differential equation between each successive pair of nodes. If the tension equals zero, which is the default, the fourth derivative of @math{x} with respect to @math{t} will equal zero at every point. In this case, @math{x} as a function of @math{t} will reduce to a cubic polynomial between each successive pair of nodes. But if the tension is nonzero, @math{x} will not be a polynomial function of @math{t}. It may be expressed in terms of exponential functions, however.
Irrespective of whether or not the spline is under tension, you may specify the `-p' option if you wish the spline to be a periodic function of @math{t}. This will only work if the @math{x} values for the first and last points in the dataset are equal. Otherwise, it would make no sense to compute a periodic interpolation.
It is sometimes useful to interpolate between data points at the same
time as they are generated by an auxiliary program. That is, it is
useful for spline
to function as a real-time filter.
spline
does not normally act as a filter, since computing an
interpolating curve that is as smooth as possible is a global task. But
if the `-f' option is specified, spline
will indeed function
as a filter. A different interpolation algorithm (cubic Bessel
interpolation, which is local rather than global) will be used. If
`-f' is specified, `-p' may not be specified. Also, if
`-f' is specified then an interpolation interval must be requested
explicitly with the `-t' option.
Cubic Bessel interpolation is inherently less smooth than the construction of a global cubic spline. If the `-f' option is specified, the slope of the spline at each node will be chosen by fitting a parabola through that node, and the two adjacent nodes. The slopes of the two interpolating segments to either side of each interior node will match at that node, but typically their curvatures will not. In mathematical terms, the interpolating curve will be continuously differentiable, but in general not twice continuously differentiable. This loss of differentiability is the price that is paid for functioning as a real-time filter.
The algorithms used by spline
are similar to those discussed in
D. Kincaid and W. Cheney, Numerical Analysis (2nd ed.,
Brooks/Cole, 1996), section 6.4, and C. de Boor, A Practical
Guide to Splines (Springer-Verlag, 1978), Chapter 4.
spline
command-line options
The options to spline
are listed below. There are three sorts of
option:
Options that take an argument are followed, in parentheses, by the type and default value of the argument.
Besides options, the command line may include the names of one or more input files. If no files are listed, the standard input is read. Unless the `-a' option is used (see below), the input is expected to be a sequence of data points, given as alternating @math{t} @w{and @math{x}} coordinates. There may be more than one dataset per input file. If the files are in ASCII format (the default), datasets are separated by blank lines.
The following options specify the type of interpolation to be performed on each dataset.
spline
may be used as a real-time filter. The slope of the
interpolating curve at each point in a dataset will be chosen by fitting
a parabola through that point and the two adjacent points in the
dataset. If `-f' is specified then the `-t' option, otherwise
optional, must be used as well. Also, if `-f' is specified then
the `-k', `-p', and `-T' options may not be used.
If `-f' is not specified, then a different (global)
interpolation algorithm will be used.
The following options specify the format of the input file(s) and the output file.
The following options request information.
spline
and the plotting utilities
package, and exit.
ode
Utility
The GNU ode
utility can produce a numerical solution to the
initial value problem for many systems of first-order ordinary
differential equations (ODE's). ode
may also be used to solve
systems of higher-order ODE's, since a simple procedure converts an
@math{n}'th-order equation into @w{@math{n} first-order} equations. The
output of ode
may easily be piped to graph
, so that one or
more solution curves may be plotted as they are generated.
Three distinct schemes for numerical solution are implemented: Runge--Kutta--Fehlberg (the default), Adams--Moulton, and Euler. The Runge--Kutta--Fehlberg and Adams--Moulton schemes are available with adaptive stepsize.
We begin with some standard definitions. A differential equation
is an equation involving an unknown function and its derivatives. A
differential equation is ordinary if the unknown function
depends on only one independent variable, often denoted @math{t}.
The order of the differential equation is the order of the
highest-order derivative in the equation. One speaks of a family, or
system of equations when more than one equation is involved. If
the equations are dependent on one another, they are said to be
coupled. A solution is any function satisfying the
equations. An initial value problem is present when there exist
subsidiary conditions on the unknown function and its derivatives, all
of which are given at the same value of the independent variable. In
principle, such an `initial condition' specifies a unique solution.
Questions about the existence and uniqueness of a solution, along with
further terminology, are discussed in any introductory text. (See
Chapter 1 of Birkhoff and Rota's Ordinary Differential
Equations. For this and other references relevant to ode
, see
section Bibliography on ode
and solving differential equations.)
In practical problems, the solution of a differential equation is usually not expressible in terms of elementary functions. Hence the need for a numerical solution.
A numerical scheme for solving an initial value problem produces an
approximate solution, using only functional evaluations and the
operations of arithmetic. ode
solves first-order initial value
problems of the form:
given the initial values for each dependent variable at the initial value of the independent variable @math{t}, i.e.,
@math{x(a) = b} @math{y(a) = c} . . . @math{z(a) = d} @math{t = a}
All schemes for numerical solution involve the calculation of an
approximate solution at discrete values of the independent variable
@math{t}, where the `stepsize' (the difference between any two
successive values of @math{t}, usually @w{denoted @math{h}}) may be
constant or chosen adaptively. In general, as the stepsize
decreases the solution becomes more accurate. In ode
, the
stepsize may be adjusted by the user.
ode
The following examples should illustrate the procedure of stating an
initial value problem and solving it with ode
. If these
examples are too elementary, see section The ode
input language formally specified, for a formal
specification of the ode
input language. There is also a
directory containing examples of ode
input, called
ode-examples
, which is distributed along with the GNU plotting
utilities.
Our first example is a simple one, namely
@math{y'(t) = y(t)}
with the initial condition
@math{y(0) = 1}
The solution to this differential equation is
In particular
to seven digits of accuracy.
You may obtain this result with the aid of ode
by typing on the
command line the sequence of commands
ode y' = y y = 1 print t, y step 0, 1
Two columns of numbers will appear. Each line will show the value of the independent variable @math{t}, and the value of the variable @math{y}, as @math{t} is `stepped' from 0 to 1. The last line will be
1 2.718282
as expected. You may use the `-p' option to change the precision. If, for example, you type `ode -p 10' rather than `ode', you will get ten digits of accuracy in the output, rather than seven (the default).
After the above output, ode
will wait for further instructions.
Entering for example the line
step 1, 0
should yield two more columns of numbers, containing the values of @math{t} and @math{y} that are computed when @w{@math{t} is} stepped back from 1 to 0. You could type instead
step 1, 2
to increase rather than decrease @math{t}. To exit ode
,
you would type a line containing only `.', i.e. a single period,
and tap `return'. ode
will also exit if it sees an end-of-file
indicator in its input stream, which you can send from your terminal by
typing control-D.
Each line of the preceding example should be self-explanatory. A
`step' statement sets the beginning and the end of an interval
over which the independent variable (here, @math{t}) will range, and
causes ode
to set the numerical scheme in motion. The initial
value appearing in the first `step' statement (i.e., 0) and the
assignment statement
y = 1
are equivalent to the initial condition @math{y(0) = 1}. The statements
`y' = y' and `y = 1' are very different: `y' = y'
defines a way of computing the derivative of @math{y}, while @samp{y
= 1} sets the initial value of @math{y}. Whenever a `step'
statement is encountered, ode
tries to step the independent
variable through the interval it specifies. Which values are to be
printed at each step is specified by the most recent `print'
statement. For example,
print t, y, y'
would cause the current value of the independent variable @math{t}, the variable @math{y}, and its derivative to be printed at each step.
To illustrate ode
's ability to take its input or the initial part
of its input from a file, you could prepare a file containing the
following lines:
# an ode to Euler y = 1 y' = y print t, y, y'
Call this file `euler'. (The `#' line is a comment line,
which may appear at any point. Everything from the `#' to the
end of the line on which it appears will be ignored.) To process
this file with ode
, you could type on your terminal
ode -f euler step 0, 1
These two lines cause ode
to read the file `euler', and the
stepping to take place. You will now get three quantities (@math{t},
@math{y}, and @math{y'}) printed at each of the values @w{of @math{t}}
between 0 and 1. At the conclusion of the stepping, ode
will wait for any further commands to be input from the terminal. This
example illustrates that
ode -f euler
is not equivalent to
ode < euler
The latter would cause ode
to take all its input from the file
`euler', while the former allows subsequent input from the
terminal. For the latter to produce output, you would need to include a
`step' line at the end of the file. You would not need to include
a `.' line, however. `.' is used to terminate input only
when input is being read from a terminal.
A second simple example involves the numerical solution of a second-order differential equation. Consider the initial value problem
@math{y"(t) = -y(t)} @math{y(0) = 0} @math{y'(0) = 1}
Its solution would be
To solve this problem using ode
, you must express this
second-order equation as two first-order equations. Toward this end you
would introduce a new function, called @math{yp} say, of the independent
variable @math{t}. The pair of equations
@math{y' = yp} @math{yp' = -y}
would be equivalent to the single equation above. This sort of reduction of an @math{n}'th order problem to @math{n} first order problems is a standard technique.
To plot the variable @math{y} as a function of the @w{variable @math{t}}, you could create a file containing the lines
# sine : y"(t) = -y(t), y(0) = 0, y'(0) = 1 sine' = cosine cosine' = -sine sine = 0 cosine = 1 print t, sine
(@math{y} and @math{yp} have been renamed sine and cosine, since that is what they will be.) Call this file `sine'. To display the generated data points on an X Window System display as they are generated, you would type
ode -f sine | graph -T X -x 0 10 -y -1 1 step 0, 2*PI .
After you type the ode
line, graph -T X
will pop up a
window, and after you type the `step' line, the generated dataset
will be drawn in it. The `-x 0 10' and `-y -1 1' options,
which set the bounds for the two axes, are necessary if you wish to
display points in real time: as they are generated. If the axis
bounds were not specified on the command line, graph -T X
would wait
until all points are read from the input before determining the bounds,
and drawing the plot.
A slight modification of this example, showing how ode
can
generate several datasets in succession and plot them on the same graph,
would be the following. Suppose that you type on your terminal the
following lines.
ode -f sine | graph -T X -C -x 0 10 -y -1 1 step 0, PI step PI, 2*PI step 2*PI, 3*PI .
Then the sine curve will be traced out in three stages. Since the
output from each `step' statement ends with a blank line,
graph -T X
will treat each section of the sine curve as a different
dataset. If you are using a color display, each of the three sections
will be plotted in a different color. This is a feature provided by
graph -T X
, which normally changes its linemode after each dataset
it reads. If you do not like this feature, you may turn it off by using
`graph -T X -B' instead of `graph -T X'.
In the above examples, you could use any of the other variants of
graph
instead of graph -T X
. For example, you could use
graph -T ps
to obtain a plot in encapsulated Postscript format,
by typing
ode -f sine | graph -T ps > plot.ps step 0, 2*PI .
You should note that of the six variants of graph
, graph -T
ps
, graph -T fig
, and graph -T hpgl
do not produce output
in real time, even when the axis bounds are specified with the `-x'
and `-y' options. So if graph -T ps
, graph -T
fig
, or graph -T hpgl
is used, the plot will be produced only
when input from ode
is terminated, which will occur when you
type `.'.
In the preceding examples, the derivatives of the dependent variables
were specified by comparatively simple expressions. They are allowed to
be arbitrarily complicated functions of the dependent variables and the
independent variable. They also may involve any of the functions that
are built into ode
. ode
has a fair number of functions
built in, including abs, sqrt, exp, log, log10,
sin, cos, tan, asin, acos, atan, sinh,
cosh, tanh, asinh, acosh, and atanh. Less familiar
functions which are built into it are besj0, besj1,
besy0, besy1, erf, erfc, inverf, lgamma,
gamma, norm, invnorm, ibeta, and igamma. These have
the same definitions as in the plotting program gnuplot
. (All
functions take a single argument, except for ibeta, which takes
three, and igamma, which takes two). ode
also knows the
meaning of the constant `PI', as the above examples show. The
names of the preceding functions are reserved, so, e.g., `cos' and
`sin' may not be used as names for variables.
Other than the restriction of avoiding reserved names and keywords, the
names of variables may be chosen arbitrarily. Any sequence of
alphanumeric characters starting with an alphabetic character may be
used; the first 32 characters are significant. It is worth noting
that ode
identifies the independent variable by the fact that it
is (or should be) the only variable that has not appeared on the left
side of a differential equation or an initial value assignment. If
there is more than than one such variable then no stepping takes place;
instead, an error message is printed. If there is no such variable,
a dummy independent variable is invented and given the name
`(indep)', internally.
ode
We explain here how to use some additional features of ode
.
However, the discussion below does not cover all of its capabilities.
For a complete list of command-line options, see section ode
command-line options.
It is easy to use ode
to create plots of great beauty. An
example would be a plot of a strange attractor, namely the Lorenz
attractor. Suppose that a file named `lorenz' contains the
following lines.
# The Lorenz model, a system of three coupled ODE's with parameter r. x' = -3*(x-y) y' = -x*z+r*x-y z' = x*y-z r = 26 x = 0; y = 1; z = 0 print x, y step 0, 200
Then executing the command
<lorenz ode | graph -T X -C -x -10 10 -y -10 10
would produce a plot of the Lorenz attractor (strictly speaking, a plot of one of its two-dimensional projections). You may produce a Postscript plot of the Lorenz attractor, and print it, by doing something like
<lorenz ode | graph -T ps -x -10 10 -y -10 10 -W 0 | lpr
The `-W 0' ("zero width") option requests that graph -T ps
use the thinnest line possible, to improve the visual appearance of the
plot on a printer or other Postscript device.
Besides plotting a visually striking object in real time, the Lorenz
attractor example shows how statements may be separated by semicolons,
rather than appearing on different lines. It also shows how to use
symbolic constants. In the description read by ode
the
parameter @math{r} is a variable like @math{x}, @math{y}, @w{and
@math{z}}. But unlike them it is not updated during stepping, since no
formula for its derivative @math{r'} is given.
Our second example deals with the interactive construction of a `phase portrait': a set of solution curves with different initial conditions. Phase portraits are of paramount interest in the qualitative theory of differential equations, and also possess @ae{}sthetic appeal.
Since a description read by ode
may contain any number of
`step' statements, multiple solution curves may be plotted in a
single run. The most recent `print' statement will be used with
each `step' statement. In practice, a phase portrait would be
drawn from a few well-chosen solution curves. Choosing a good set of
solution curves may require experimentation, which makes interactivity
and real-time plotting all-important.
As an example, consider a so-called Lotka--Volterra predator--prey model. Suppose that in a lake there are two species of fish: A (the prey) who live by eating a plentiful supply of plants, and B (the predator) who eat A. Let @math{x(t)} be the population of A and @math{y(t)} the population of B at @w{time @math{t}}. A crude model for the interaction of A and B is given by the equations
@math{x' = x(a-by)} @math{y' = y(cx-d)}
where @math{a, b, c, d} are positive constants. To draw a phase portrait for this system interactively, you could type
ode | graph -T X -C -x 0 5 -y 0 5 x' = (a - b*y) * x y' = (c*x - d) * y a = 1; b = 1; c = 1; d = 1; print x, y x = 1; y = 2 step 0, 10 x = 1; y = 3 step 0, 10 x = 1; y = 4 step 0, 10 x = 1; y = 5 step 0, 10 .
Four curves will be drawn in succession, one per `step' line. They
will be periodic; this periodicity is similar to the fluctuations
between predator and prey populations that occur in real-world
ecosystems. On a color display the curves will appear in different
colors, since by default, graph -T X
changes the line mode
between datasets. That feature may be turned off by using
`graph -T X -B' rather than `graph -T X'.
It is sometimes useful to use ode
and graph
to plot
discrete points, which are not joined by line segments to form a curve.
Our third example illustrates this. Suppose the file `atwoods'
contains the lines
m = 1 M = 1.0625 a = 0.5; adot = 0 l = 10; ldot = 0 ldot' = ( m * l * adot * adot - M * 9.8 + m * 9.8 * cos(a) ) / (m + M) l' = ldot adot' = (-1/l) * (9.8 * sin(a) + 2 * adot * ldot) a' = adot print l, ldot step 0, 400
The first few lines describe the functioning of a so-called swinging Atwood's machine. An ordinary Atwood's machine consists of a taut cord draped over a pulley, with a mass attached to the cord at each end. Normally, the heavier mass (@math{M)} would win against the lighter mass (@math{m)}, and draw it upward. A swinging Atwood's machine allows the lighter mass to swing back and forth as well as move vertically.
The `print l, ldot' statement requests that the vertical position and vertical velocity of the lighter mass be printed out at each step. If you run the command
<atwoods ode | graph -T X -x 9 11 -y -1 1 -m 0 -S 1 -X l -Y ldot
you will obtain a real-time plot. The `-m 0' option requests that successive data points not be joined by line segments, and the `-S 1' option requests that plotting symbol #1 (a dot) be plotted at the location of each point. As you will see if you run this command, the heavy mass does not win against the lighter mass. Instead the machine oscillates non-periodically. Since the motion is non-periodic, the plot benefits from being drawn as a sequence of unconnected points.
We conclude by mentioning a few features of ode
that may be
useful when things are not going quite right. One of them is the
`examine' statement. It may be used to discover pertinent
information about any variable in a system. For details, see section The ode
input language formally specified.
Another useful feature is that the `print' statement may be used to print out more than just the value of a variable. As we have seen, if the name of the variable is followed by `'', the derivative of the variable will be printed instead. In a similar way, following the variable name with `?', `!', or `~' prints respectively the relative single-step error, the absolute single-step error, or the accumulated error (not currently implemented). These quantities are discussed in section Numerical error and how to avoid it.
The `print' statement may be more complicated than was shown in the preceding examples. Its general structure is
print <pr-list> [every <const>] [from <const>]
The bracket notation `[...]' means that the enclosed statements are optional. Until now we have not mentioned the `every' clause or the `from' clause. The <pr-list> is familiar, however; it is simply a comma-separated list of variables. For example, in the statement
print t, y, y' every 5 from 1
the <pr-list> is <t, y, y'>. The clauses `every 5' and `from 1' specify that printing should take place after every fifth step, and that the printing should begin when the independent variable @math{t} reaches 1. An `every' clause is useful if you wish to `thin out' the output generated by a `step' statement, and a `from' clause is useful if you wish to view only the final portion of a solution curve.
ode
command-line options
The command-line options to ode
are listed below. There are
several sorts of option:
The following option affects the way input is read.
The following options affect the output format.
The following options specify the numerical integration scheme. Only one of the three basic option `-R', `-A', and `-E' may be specified. The default is `-R' (Runge--Kutta--Fehlberg).
The following options set the error bounds on the numerical solution scheme.
ode
to
continue even if this ceiling is exceeded. This may result in large
numerical errors.
Finally, the following options request information.
ode
and the plotting utilities
package, and exit.
ode
is always in one of two states:
ode
moves from the first to the second state after it sees and
processes a `step' line. It returns to the first state after
the generated output has been printed. Errors may occur in either the
`reading' state or the `solving' state, and may terminate computations
or even cause ode
to exit. We now explain the possible sorts of
error.
While reading input, ode
may encounter a syntax error: an
ungrammatical line that it is unable to parse. (For a summary of its
input grammar, see section The ode
input language formally specified.) If so, it emits the error
message
ode::nnn: syntax error
where `nnn' is the number of the line containing the error. When the `-f filename' option is used to specify an input file, the error message will read
ode:filename:nnn: syntax error
for errors encountered inside the input file. Subsequently, when
ode
begins reading the standard input, line numbers will start
over again from 1.
No effort is made to recover from syntax errors in the input. However, there is a meager effort to resynchronize, so that more than one syntax error in a file may be found at the same time.
It is also possible that a fatal arithmetic exception (such as a
division by zero, or a floating point overflow) may occur while
ode
is reading input. If such an exception occurs, ode
will print an "Floating point exception" error message and exit.
Arithmetic exceptions are machine-dependent. On some machines, the
line
y = 1/0
would induce an arithmetic exception. Also on some machines (not necessarily the same ones), the lines
y = 1e100 z = y^4
When ode
is in the `solving' state, i.e., computing a numerical
solution, similar arithmetic exceptions may occur. If so, the solution
will be interrupted and a message resembling
ode: arithmetic exception while calculating y'
will be printed. However, ode
will not exit; the exception will
be `caught'. ode
itself recognizes the following exceptional
conditions: square root of a negative number, logarithm of a
non-positive number, and negative number raised to a non-integer power.
ode
will catch any of these operations before it is performed,
and print an error message specifying which illegal operation it has
encountered.
ode: square root of a negative number while calculating y'
would be a typical error message.
If the machine on which ode
is running supports the
`matherr' facility for reporting errors in the computation of
standard mathematical functions, it will be used. This facility reports
domain errors and range errors (overflows, underflows, and losses of
significance) that could occur when evaluating such functions as
`log', `gamma', etc.; again, before they are performed. If
the matherr
facility is present, the error message will be fairly
informative. For example, the error message
ode: range error (overflow) in lgamma while calculating y'
could be generated if the logarithmic gamma function `lgamma' is evaluated at a value of its argument that is too large. The generation of any such message, except a message warning of an underflow, will cause the numerical solution to be interrupted.
There is another sort of error that may occur during numerical solution:
the condition that an error ceiling, which may be set by the user with
the `-r' option or the `-e' option, is exceeded. This too
will cause the numerical solution to be abandoned, and ode
to
switch back to reading input.
This discussion is necessarily incomplete. Entire books exist on any
subject mentioned below (e.g., floating point error). Our goals are
modest: first, to introduce the basic notions of error analysis as they
apply to ode
; second, to steer you around the more obvious
pitfalls. You should look through a numerical analysis text (e.g.,
Atkinson's Introduction to Numerical Analysis) before beginning
this discussion.
We begin with some key definitions. The error of greatest concern is the difference between the actual solution and the numerical approximation to the solution; this is termed the accumulated error, since the error is built up during each numerical step. Unfortunately, an estimate of this error is usually not available without knowledge of the actual solution. There are, however, several more usable notions of error. The single-step error, in particular, is the difference between the actual solution and the numerical approximation to the solution after any single step, assuming the value at the beginning of the step is correct.
Where does numerical error come from? There are two sources. The first
is the finite precision of machine computation. All computers work with
floating point numbers, which are not real numbers, but only an
approximation to real numbers. However, all computations performed by
ode
are done to double precision, so floating point error tends
to be relatively small. You may nonetheless detect the difference
between real numbers and floating point numbers by experimenting with
the `-p 17' option, which will print seventeen significant digits.
On most machines, that is the precision of a double precision
floating point number.
The second source of numerical error is often called the
theoretical truncation error. It is the difference between
the actual solution and the approximate solution due solely to the
numerical scheme. At the root of many numerical schemes is an infinite
series; for ordinary differential equations, it is a Taylor expansion.
Since the computer cannot compute all the terms in an infinite series,
a numerical scheme necessarily uses a truncated series; hence the
term. The single-step error is the sum of the theoretical truncation
error and the floating point error, though in practice the floating
point error is seldom included. The single-step error estimated by
ode
consists only of the theoretical truncation error.
We say that a numerical scheme is stable, when applied to a particular initial value problem, if the error accumulated during the solution of the problem over a fixed interval decreases as the stepsize decreases; at least, over a wide range of step sizes. With this definition both the Runge--Kutta--Fehlberg (`-R') scheme and the Adams--Moulton (`-A') scheme are stable (a statement based more on experience than on theoretical results) for a wide class of problems.
After these introductory remarks, we list some common sources of accumulated error and instability in any numerical scheme. Usually, problems with large accumulated error and instability are due to the single-step error in the vicinity of a `bad' point being large.
ode
should not be used to generate a numerical solution on any
interval containing a singularity. That is, ode
should not be
asked to step over points at which the system of differential equations
is singular or undefined.
You will find the definitions of singular point, regular singular point,
and irregular singular point in any good differential equations text.
If you have no favorite, try Birkhoff and Rota's Ordinary
Differential Equations, Chapter 9. Always locate and classify the
singularities of a system, if any, before applying ode
.
ode
to yield an accurate numerical solution on an interval,
the true solution must be defined and well-behaved on that interval.
The solution must also be real. Whenever any of these conditions is
violated, the problem is said to be ill-posed. Ill-posedness may
occur even if the system of differential equations is well-behaved on
the interval. Strange results, e.g., the stepsize suddenly shrinking to
the machine limit or the solution suddenly blowing up, may indicate
ill-posedness.
As an example of ill-posedness (in fact, an undefined solution) consider
the innocent-looking problem:
The solution on the domain @math{t > 0} is
@math{y(t) = -1/t}.With this problem you must not compute a numerical solution on any interval that includes @math{t=0}. To convince yourself of this, try to use the `step' statement
step 1, -1on this system. How does
ode
react?
As another example of ill-posedness, consider the system
@math{y'=1/y}which is undefined at @math{y=0}. The general solution is In general, when using a constant stepsize you should be careful not to `step over' bad points or bad regions. When allowed to choose a stepsize adaptively,
ode
will often spot bad points, but not
always.
@math{y' = 2x} @math{x' = 2y}has only one critical point, at @math{(x,y) = (0,0)}. A critical point is sometimes referred to as a stagnation point. That is because a system at a critical point will remain there forever, though a system near a critical point may undergo more violent motion. Under some circumstances, passing near a critical point may give rise to a large accumulated error. As an exercise, solve the system above using
ode
, with the
initial condition @math{x(0) = y(0) = 0}. The solution should be
constant in time. Now do the same with points near the critical point.
What happens?
You should always locate the critical points of a system before
attempting a solution with ode
. Critical points may be
classified (as equilibrium, vortex, unstable, stable, etc.) and this
classification may be of use. To find out more about this, consult
any book dealing with the qualitative theory of differential equations
(e.g., Birkhoff and Rota's Ordinary Differential Equations,
Chapter 6).
ode
are bad in the sense that
instability appears to be present, or an unusually small stepsize needs
to be chosen needed in order to reduce the single-step error to
manageable levels, it may simply be that the numerical scheme being used
is not suited to the problem. For example, ode
currently has no
numerical scheme which handles so-called `stiff' problems very well.
As an example, you may wish to examine the stiff problem:
@math{y' = -100 + 100t + 1} @math{y(0)=1}on the domain @math{[0,1]}. The exact solution is It is a useful exercise to solve this problem with
ode
using
various numerical schemes, stepsizes, and relative single-step error
bounds, and compare the generated solution curves with the actual
solution.
There are several rough and ready heuristic checks you can perform on
the accuracy of any numerical solution produced by ode
. We
discuss them in turn.
# an equation arising in QCD (quantum chromodynamics) f' = fp fp' = -f*g^2 g' = gp gp' = g*f^2 f = 0; fp = -1; g = 1; gp = -1 print t, f step 0, 5Next make a file named `stability', containing the lines:
: sserr is the bound on the relative single-step error for sserr do ode -r $sserr < qcd done | spline -n 500 | graph -T X -CThis is a `shell script', which when run will superimpose numerical solutions with specified bounds on the relative single-step error. To run it, type:
sh stability 1 .1 .01 .001and a plot of the solutions with the specified error bounds will be drawn. The convergence, showing stability, should be quite illuminating.
The time required for ode
to solve numerically a system of
ordinary differential equations depends on a great many factors. A
few of them are: number of equations, complexity of equations (number
of operators and nature of the operators), and number of steps taken
(a very complicated function of the difficulty of solution, unless
constant stepsizes are used). The most effective way to gauge the time
required for solution of a system is to clock a short or imprecise run
of the problem, and reason as follows: the time required to take two
steps is roughly twice that required for one; and there is a
relationship between the number of steps required and the relative error
ceiling chosen. That relationship depends on the numerical scheme being
used, the difficulty of solution, and perhaps on the magnitude of the
error ceiling itself. A few carefully planned short runs may be
used to determine this relationship, enabling a long but imprecise run
to be used as an aid in projecting the cost of a more precise run over
the same region. Lastly, if a great deal of data is printed, it is
likely that more time is spent in printing the results than in computing
the numerical solution.
ode
input language formally specified
The following is a formal specification of the grammar for ode
's
input language, in Backus--Naur form. Nonterminal symbols in the
grammar are enclosed in angle brackets. Terminal tokens are in all
capitals. Bare words and symbols stand for themselves.
<program> ::= ... empty ... | <program> <statement> <statement> ::= SEP | IDENTIFIER = <const> SEP | IDENTIFIER ' = <expression> SEP | print <printlist> <optevery> <optfrom> SEP | step <const> , <const> , <const> SEP | step <const> , <const> SEP | examine IDENTIFIER SEP <printlist> ::= <printitem> | <printlist> , <printitem> <printitem> ::= IDENTIFIER | IDENTIFIER ' | IDENTIFIER ? | IDENTIFIER ! | IDENTIFIER ~ <optevery> ::= ... empty ... | every <const> <optfrom> ::= ... empty ... | from <const> <const> ::= <expression> <expression> ::= ( <expression> ) | <expression> + <expression> | <expression> - <expression> | <expression> * <expression> | <expression> / <expression> | <expression> ^ <expression> | FUNCTION ( <expression> ) | - <expression> | NUMBER | IDENTIFIER
Since this grammar is ambiguous, the following table summarizes the precedences and associativities of operators within expressions. Precedences decrease from top to bottom.
Class Operators Associativity Exponential ^ right Multiplicative * / left Additive + - left
As noted in the grammar, there are six types of nontrivial statement. We now explain the effects (the `semantics') of each type, in turn.
"y" is a dynamic variable value:2.718282 prime:2.718282 sserr:1.121662e-09 aberr:3.245638e-09 acerr:0 code: push "y"The phrase `dynamic variable' means that there is a differential equation describing the behavior of y. The numeric fields in the table are:
The grammar for the ode
input language contains four types of
terminal token: FUNCTION, IDENTIFIER, NUMBER, and
SEP. They have the following meanings.
gnuplot
. All functions take a
single argument, except for ibeta, which takes three, and
igamma, which takes two. For trigonometric functions, all arguments
are expressed in radians. The atan function is defined to give a
value between -PI/2 and PI/2 (inclusive).
In the ode
input language, upper and lower-case letters are
distinct. Comments begin with the character `#' and continue to
the end of the line. Long lines may be continued onto a second line by
ending the first line with a backslash (`\'). That is because
the combination backslash-newline is equivalent to a space.
Spaces or tabs are required in the input whenever they are needed to separate identifiers, numbers, and keywords from one another. Except as separators, they are ignored.
ode
and solving differential equationsode
.
ode
: A
numerical simulation of ordinary differential equations,"
pp. 480--481 in Proceedings of the Conference on Computers in
Physics Instruction, Addison--Wesley, 1990.
libplot
, a Function Library
libplot
is a library of functions for device-independent
two-dimensional vector graphics. The graphical objects which it can
draw include paths, circles and ellipses, points, markers, and `adjusted
labels' (justified text strings). A path is a sequence of
line segments, circular arcs, and/or elliptic arcs, which may be open or
closed. User-specified filling of paths, circles, and ellipses is
supported (fill color, as well as pen color, may be specified).
There is support for maintaining a Postscript-style stack of graphics
contexts, i.e., a stack of drawing attribute sets. User-specifiable
attributes other than pen color and fill color include path-related
attributes such as line type and line width, and text-related attributes
such as font name, font size, and text angle.
The fundamental abstraction provided by libplot
is that of a
Plotter. A Plotter is an object with an interface for the
drawing of vector graphics which is similar to the interface provided by
a traditional pen plotter. There are several types of Plotter, which
differ in the display device they produce output for. Any number of
Plotters, of the same or different types, may exist simultaneously in an
application.
The drawing operations supported by Plotters of different types are
identical, in agreement with the principle of device independence. So a
graphics application that is linked with libplot
may easily be
written so as to produce output for any or all of the supported display
devices.
The following are the currently supported types of Plotter.
idraw
drawing editor.
xfig
drawing editor. The xfig
editor will export
drawings in various other formats for inclusion in documents.
xterm
, the X Window System terminal
emulation program. The DOS version of kermit
also includes such
an emulator.
plot
. (See section The plot
Utility.)
A distinction among these types of Plotter is that all except X and X Drawable Plotters write graphics to a file or other output stream. An X Plotter pops up its own windows, and an X Drawable Plotter manipulates one or two X drawables.
Another distinction is that X, X Drawable, Tektronix and Metafile Plotters are real-time. This means that they draw graphics or write to an output stream as the drawing operations are invoked on them. Postscript, Fig and HP-GL Plotters are not real-time, since their output streams can only be emitted after all functions have been called. For a Postscript Plotter this is because a `bounding box' line must be placed at the head of the output file. For a Fig Plotter it is because color definitions must be placed at the head of the output file.
The most important operations supported by any Plotter are openpl
and closepl
, which open and close it. Graphics may be drawn,
and drawing attributes set, only within an
openpl
...closepl
pair. In principle, any Plotter may
be opened and closed arbitrarily many times. The graphics produced by
each openpl
...closepl
pair constitute a `page'. An
X Plotter displays each page in a separate X window, and an
HP-GL Plotter renders each page as a separate physical page. X
Drawable Plotters and Tektronix Plotters manipulate a single drawable
or display, on which pages are displayed in succession.
There is a minor problem with extending these semantics to Postscript
and Fig Plotters. The closepl
operation ensures that all
graphical objects that have been drawn are written to the output. But
output files in Postscript and Fig format may not be concatenated. For
this reason, all Plotters support an additional operation:
outfile
. The output stream for a Plotter, if it has one, may be
altered by invoking outfile
on it. outfile
may only
be invoked outside an openpl
...closepl
pair. By using
outfile
, a programmer may produce multipage graphics output from
Postscript and Fig Plotters. Its use in other contexts is deprecated.
There are several other basic operations which any Plotter supports. The `graphics display' drawn in by a Plotter is a square or rectangular region on a display device. But when using any Plotter to draw graphics, an application must specify the coordinates of graphical objects in a device-independent `user frame', rather than in device coordinates. A Plotter relates the user frame to the device frame by performing a user-specified affine coordinate transformation.
Immediately after invoking openpl
to open a Plotter, an
application should invoke the space
operation to initialize this
affine transformation from the user frame to the device frame. This
invocation determines the rectangular region (in user coordinates) that
will be mapped by the Plotter to the graphics display. The affine
transformation may be updated at any later time, if desired, by invoking
fconcat
. The fconcat
operation will `concatenate' (i.e.,
compose) the current affine transformation transformation with any
specified affine map. This sort of concatenation is a capability
familiar from, e.g., Postscript.
Any Plotter maintains a Postscript-style stack of graphics contexts.
A graphics context includes such modal drawing attributes as
graphics cursor position, line mode, line width, pen and fill colors,
and the font used for drawing text. It also includes the current
affine map from the user frame to the device frame. The state of any
uncompleted path (if any) is included as well, since paths may
be drawn incrementally, one segment (line segment or arc) at a time.
The current graphics context may be pushed onto the stack of graphics
contexts by calling savestate
, and popped off by calling
restorestate
.
libplot
If you are writing an application in C that will use libplot
to
draw graphics, you need to know how to create and select Plotters.
The newpl
function will create a Plotter of specified type. Its
first argument may be "X", "Xdrawable", "ps", "fig", "hpgl", "tek", or
"meta". It returns an integer (a "handle") that may be used to
refer to the Plotter. Before using a Plotter that you have created
(i.e., before invoking any of the libplot
operations on it),
you must select the Plotter by calling selectpl
. Only one
Plotter may be selected at a time, but by calling selectpl
you
may switch from Plotter to Plotter at any time, even when the selected
Plotter is open. A Plotter that is not currently selected may be
deleted, and its storage freed, by calling deletepl
.
Strictly speaking, you do not need to call newpl
,
selectpl
, or deletepl
in order to draw graphics. That is
because at startup, a single Metafile Plotter that writes to standard
output (with handle `0') is automatically created and selected. The
presence of this default Plotter is for compatibility with pre-GNU
versions of libplot
. Of course, you may not wish to obtain
output in metafile format, and you may not wish to write to standard
output.
The source code for a graphics application written in C, if it is to use
libplot
, should contain the lines
#include <stdio.h> #include <plot.h>
The header file plot.h
is distributed with libplot
, and
should have been installed on your system where your C compiler will
find it. It contains prototypes for each of the functions in
libplot
and some miscellaneous definitions. It may be used
with C++ programs as well as C programs.
To link your application with libplot
, you would use the
appropriate `-l' option(s) on the command line when compiling it.
You would use
-lplot -lXaw -lXmu -lXt -lXext -lX11 -lm
(or perhaps `-lplot -lXm -lXt -lXext -lX11 -lm', `-lplot -lXm
-lXt -lXext -lX11 -lm -lc -lgen', or `-lplot -lXm -lXt -lXext -lX11
-lm -lc -lPW', on systems that provide Motif widgets instead of Athena
widgets). Note that on most systems libplot
is installed as a
DLL (dynamically linked library, or `shared' library). This means that
the linking with your application will take place at run time rather
than compile time. The environment variable LD_LIBRARY_PATH
lists the directories which will be searched for DLL's at run time. For
your application to be executable, this environment variable should
include the directory in which libplot
is stored.
The following is a sample application that uses libplot
. It
draws an intricate and beautiful path (Bill Gosper's "C" curve,
discussed as Item #135 in HAKMEM, MIT Artificial Intelligence
Laboratory Memo #239, 1972). As the numeric constant
MAXORDER
(here equal to 10) is increased, the path will
take on the shape of a curly letter "C", which is the envelope
of a myriad of epicyclic octagons.
#include <stdio.h> #include <plot.h> #define MAXORDER 10 void draw_c_curve (double dx, double dy, int order) { if (order >= MAXORDER) fcontrel (dx, dy); /* continue path along (dx, dy) */ else { draw_c_curve (0.5 * (dx - dy), 0.5 * (dx + dy), order + 1); draw_c_curve (0.5 * (dx + dy), 0.5 * (dy - dx), order + 1); } } int main () { int handle; { /* create a Postscript Plotter that writes to standard output */ handle = newpl ("ps", stdin, stdout, stderr); selectpl (handle); /* select the Plotter */ } if (openpl () < 0) /* open Plotter */ { fprintf (stderr, "Couldn't open Plotter\n"); return 1; } fspace (0.0, 0.0, 1000.0, 1000.0); /* choose coors for user frame */ flinewidth (0.25); /* width of lines in user frame */ pencolorname ("red"); /* path will be drawn in red */ erase (); /* erase Plotter's graphics display */ fmove (600.0, 300.0); /* position the graphics cursor */ draw_c_curve (0.0, 400.0, 0); /* close plotter, i.e., write output */ if (closepl () < 0) { fprintf (stderr, "Couldn't close Plotter\n"); return 1; } selectpl (0); /* select default Plotter */ deletepl (handle); /* clean up by deleting Plotter we used */ return 0; }
As you can see, this application begins by calling the newpl
function to create a Postscript Plotter. The three arguments
stdin
, stdout
, stderr
require a bit of explanation.
Currently, Plotters are write-only: they are not interactive, so they do
not read from an input stream. So the second argument to newpl
is a dummy. If non-NULL, the third and fourth arguments must be an
output stream and an error stream, both of which are opened for writing.
This is the case for Plotters other than X Plotters, at least.
The graphical objects that are drawn between any
openpl
...closepl
pair will be written to the output
stream, and error messages (if any) will be written to the error
stream, provided that it is non-NULL. All plotters other than X
Plotters and X Drawable Plotters use an output stream to draw
graphics.
The application draws the "C" curve recursively, and (since a
Postscript Plotter is selected) writes a Postscript file to standard
output when closepl
is called. The drawing of the curve is
accomplished by invoking fmove
on the Plotter to position the
graphics cursor, and then repeatedly invoking fcontrel
. The
fcontrel
operation continues a path by adding a line segment
to it. The endpoint of each line segment is specified in relative
coordinates, as an offset in the user frame.
Specifying "fig", "hpgl", "tek", or "meta" as the first argument in the
call to newpl
, instead of "ps", will cause output to be written
to the output stream in the specified format, instead of Postscript.
If "X" is specified as the first argument of newpl
, the curve
will be drawn in a popped-up X window, and the output stream
argument will be ignored. Which X Window System display the window
pops up on is determined by the DISPLAY driver parameter
(section Device driver parameters), or if that parameter has not been set, by the
DISPLAY environment variable.
Specifying "meta" as the Plotter type may be useful if you wish to avoid
recompilation for different output devices. Metafile output may be
piped to the plot
utility and converted to any other supported
output format, or displayed in an X window. See section The plot
Utility.
If you specify "Xdrawable" as the Plotter type, you will need to create
at least one X drawable (i.e., window or a pixmap), and by invoking
the parampl
function before newpl
is called, pass it to
libplot
as a driver parameter. For a list of supported driver
parameters, section Device driver parameters.
libplot
: A detailed listing
The functions in GNU libplot
include the three Plotter
manipulation functions discussed in the previous section (newpl
,
selectpl
, and deletepl
), which are specific to the
C binding. The also include 80 basic functions: parampl
,
a function that sets low-level options for subsequently created Plotters
(section Device driver parameters), and 79 functions that operate on the
currently selected Plotter.
These 80 functions are divided into the four sets tabulated below.
Many functions come in two versions: integer and double precision
floating point. Internally, libplot
uses double precision
floating point. The integer versions are provided for backward
compatibility. If there are two versions of a function, the name of the
floating point version begins with the letter `f'.
Many functions come in both absolute and relative versions, also. The latter use relative coordinates (i.e., coordinates relative to the current position of the graphics cursor), and their names end in `rel'.
Currently, only a few functions have meaningful return values.
The following are libplot
's "setup functions," which
initialize, open, or close a Plotter. They are listed in the
approximate order in which they would be called.
libplot
parameter
parameter to value. Parameters are used for setting
low-level device driver options. The parameter values in effect at the
time any Plotter is created are copied into it. The most important
parameters are DISPLAY
, which specifies the X Window System
display that an X Plotter will use, and PAGESIZE
, which
affects Postscript, Fig, and HP-GL Plotters.
For most parameters, the value should be a char *
, i.e., a
string. See section Device driver parameters.
openpl
. Future releases
may support window re-use.
openpl
...closepl
pair are
still visible and are liable to be overwritten when openpl
is
next invoked. For such Plotters, you may wish to invoke erase
immediately after openpl. Currently, only X Drawable Plotters
and Tektronix Plotters are persistent. Future releases may support
persistence for X Plotters also.
The following are the libplot
functions which, when invoked on a
Plotter, cause it to draw objects (paths, circles, ellipses, points,
markers, and text strings) on the associated graphics display. A
path is a sequence of line segments and arcs (either circular or
elliptic).
textangle
has
been called.
arc
and farc
, but use
cursor-relative coordinates.
pc
=(xc,yc), p0
=(x0,y0), and
p1
=(x1,y1) that define a so-called quarter ellipse.
This is an elliptic arc from p0
to p1
with center
pc
. If the graphics cursor is at point p0
and a path is
under construction, the quarter-ellipse is added to it. Otherwise the
path under construction (if any) is ended, and the quarter-ellipse
begins a new path. In all cases the graphics cursor is moved to
p1
.
The quarter-ellipse is an affinely transformed version of a quarter
circle. It is drawn so as to have control points p0
,
p1
, and @math{p0
+p1
-pc
}. This means that it
is tangent at p0
to the line segment joining p0
to
@math{p0
+p1
-pc
}, and is tangent at p1
to the
line segment joining p1
to @math{p0
+p1
-pc
}.
So it fits snugly into a triangle with these three control points as
vertices. Notice that the third control point is the reflection of
pc
through the line joining p0
and p1
.
ellarcrel and fellarcrel are similar to ellarc and
fellarc, but use cursor-relative coordinates.
The following are the libplot
functions which, when invoked on a
Plotter, set its drawing attributes, or save them or restore them.
Note that setting any path-related drawing attribute automatically
terminates the path under construction (if any), as if the
endpath
operation had been invoked.
HPGL_VERSION
is set to a value less than "2"
(the default). See section Device driver parameters.
HPGL_VERSION
is equal to "1.5" or
"2" (the default). Also, white filling is fully supported only
if the value of the parameter HPGL_VERSION
is "2" and the
value of the parameter HPGL_OPAQUE_MODE
is "yes". See section Device driver parameters.
HPGL_VERSION
is set to a value less than "2"
(the default). See section Device driver parameters.
"solid" -------------------------------- "dotted" - - - - - - - - - - - - - - - - "dotdashed" ----------- - ----------- - "shortdashed" -- -- "longdashed" ------- -------
HPGL_VERSION
is set to a value less than "2" (the default;
see section Device driver parameters).
HPGL_VERSION
is "2" (the default), and the value of the
parameter HPGL_OPAQUE_MODE
is "yes". See section Device driver parameters.
HPGL_VERSION
is "2" (the default), and the value of the
parameter HPGL_OPAQUE_MODE
is "yes". See section Device driver parameters.
libplot
's drawing parameters, which are set by the attribute
functions documented in this section. So popping off the graphics
context restores the drawing parameters to values they previously had.
A path under construction is regarded as part of the graphics
context. For this reason, calling restorestate automatically calls
endpath to terminate the path under construction, if any. All
graphics contexts on the stack are popped off when closepl
is
called, as if restorestate
had been called repeatedly.
libplot
's drawing parameters, which are set by the attribute
functions documented in this section. A path under construction,
if any, is regarded as part of the drawing state. That is because
paths may be drawn incrementally, one segment (line segment, circular
arc segment, or elliptic arc segment) at a time. When a graphics
context is returned to, the path under construction may be continued.
The following four libplot
functions, when invoked on a Plotter,
affect the affine transformation it employs for mapping from the user
frame to the device frame. They may be viewed as performing
transformations of the user frame. Their names resemble those of the
corresponding functions in the Postscript language. For information on
how to use them to draw graphics efficiently, consult any good book on
Postscript programming, or the Postscript Language Reference
Manual.
In designing the libplot
library, every effort has been made to
make the Plotter interface independent of the type of Plotter, i.e.,
independent of the type of display device that the Plotter drives.
Device-dependence has been kept to a minimum, and is captured by a small
number of device driver parameters.
Each driver parameter has a value that is allowed to be a generic
pointer (a void *
). For most parameters, this value should
be a string (a char *
). A value for any parameter may be
specified by calling the parampl
function. This function may be
called any number of times. Calling parampl
on a parameter is
said to `set' the parameter. A parameter may be unset by calling
parampl
with a value argument of NULL.
The parampl
function does not operate on any particular Plotter:
it belongs to libplot
as a whole. The parameter values used
by any Plotter are constant over the lifetime of the Plotter, and are
essentially those that were in effect when the Plotter was created. The
following rule applies. If at Plotter creation time a parameter is set,
the value specified by the most recent call to parampl
will be
the value used by the Plotter. If at Plotter creation time a parameter
is not set, its default value will be used, unless there is an
environment variable of the same name, in which case the value of that
environment variable will be used. This rule increases run-time
flexibility: an application programmer may allow non-critical driver
parameters to be specified by the user, via environment variables.
The following are the currently recognized parameters. The most
important parameters are DISPLAY
, which affects X Plotters,
and PAGESIZE
, which affects Postscript, Fig, and HP-GL Plotters.
These two parameters are listed first and the others alphabetically.
Many of the parameters, such as the several whose names begin with
"HPGL", affect only a single type of Plotter.
DISPLAY
PAGESIZE
xfig
display, with width equal to the
width of the specified page. For HP-GL Plotters, fine control over the
positioning of the graphics display on the page may be accomplished by
setting the HPGL_XOFFSET
and HPGL_YOFFSET
parameters.
HPGL_ASSIGN_COLORS
HPGL_VERSION
is "2". "no" means to draw with a fixed
set of pens, specified by setting the HPGL_PENS
parameter. "yes"
means that pen colors will not restricted to the palette specified in
HPGL_PENS
: colors will be assigned to "logical pens" in the
range #1...#31, as needed. Not all HP-GL/2 devices allow the
assignment of colors to logical pens. In particular, HP-GL/2 pen
plotters do not. So this parameter should be used with caution.
HPGL_OPAQUE_MODE
HPGL_VERSION
is "2". "yes" means that pen #0 should
be used as an opaque white pen, permitting the drawing of white lines
and the filling of objects with opaque white. Not all HP-GL/2 devices
allow the use of pen #0 as an opaque white pen. In particular,
HP-GL/2 pen plotters do not. So this parameter should be used
with caution.
HPGL_PENS
HPGL_VERSION
is "2" and "1=black" if the value of
HPGL_VERSION
is "1" or "1.5".) Relevant only to HP-GL
Plotters. The set of available pens; the format should be
self-explanatory. The color for any pen in the range #1...#31 may
be specified. For information on what color names are recognized, see
section Specifying Colors by Name. Pen #1 must always be present, though it need
not be black. Any other pen in the range #1...#31 may be omitted.
HPGL_VERSION
HPGL_XOFFSET
HPGL_YOFFSET
MAX_LINE_LENGTH
META_PORTABLE
ROTATE
TERM
xterm
, xterms
, or kterm
, it is taken as a sign
that the current application is running in an X Window System VT100
terminal emulator: an xterm
. Before drawing graphics, a
Tektronix Plotter will emit an escape sequence that causes the terminal
emulator's auxiliary Tektronix window, which is normally hidden, to
pop up. After the graphics are drawn, an escape sequence that
returns control to the original VT100 window will be emitted. The
Tektronix window will remain on the screen.
If the value of is kermit
, ansi.sys
, ansissys
,
ansi.sysk
, or ansisysk
, it is taken as a sign that the
current application is running in the VT100 terminal emulator provided
by the DOS version of kermit
. Before drawing graphics, a
Tektronix Plotter will emit an escape sequence that switches the
terminal emulator to Tektronix mode. Also, some of the Tektronix
control codes output by the Plotter will be kermit
-specific.
There will be a limited amount of color support, which is not normally
the case (the 16 ansi.sys
colors will be supported). After
drawing graphics, the Plotter will emit an escape sequence that returns
the emulator to VT100 mode. The key sequence `ALT minus' may be
employed manually within kermit
to switch between the two modes.
VANISH_ON_DELETE
XDRAWABLE_DISPLAY
Display *
, a pointer to the X display with which the
drawable(s) to be drawn in are associated.
XDRAWABLE_DRAWABLE1
XDRAWABLE_DRAWABLE2
Drawable *
, a
pointer to a drawable to be drawn in. A `drawable' is either a
window or a pixmap. At the time an X Drawable Plotter is created,
at least one of the two parameters must be set.
X Drawable Plotters support simultaneous drawing in two drawables
because it is often useful to be able to draw graphics simultaneously in
both an X window and its background pixmap. If two drawables are
specified, they must have the same dimensions and depth, and be
associated with the same X display.
There is is one other low-level parameter worth mentioning. An X
Plotter always checks the value of the X resource
Xplot.geometry
. It uses this value, which is a string that may
be set by the user, as the size of its graphics display in terms of
pixels. The default value is "570x570". In future releases it will be
possible to set the size of an X Plotter graphics display by setting
a driver parameter.
The libplot
library and applications linked with it, such as
graph
and plot
, can draw text strings in a wide variety of
fonts. Text strings may include characters from more than one font in a
typeface, and may include superscripts, subscripts, and square roots.
A wide variety of plotting symbols can also be drawn. The following
sections explain how to use these features.
The libplot
library and applications linked with it, such as
graph
and plot
, can use many fonts. These include 16
Hershey fonts, 35 Postscript fonts, and 45 PCL 5 fonts. We call
these 96 fonts the `built-in' fonts. The Hershey fonts are so-called
vector fonts, constructed from stroked characters digitized c.
1967 by Dr. Allen V. Hershey at the U.S. Naval Surface Weapons
Center in Dahlgren, VA. The 35 Postscript fonts are the fonts
resident in all modern Postscript printers, and the 45 PCL 5 fonts
are the fonts resident in modern Hewlett--Packard LaserJet printers and
plotters. (The old LaserJet III, which was Hewlett--Packard's first
PCL 5 printer, supported only 8 of the 45.)
The Hershey fonts may be used by all types of Plotter supported by
libplot
, and the Postscript fonts may be used by all types of
Plotter except HP-GL and Tektronix. So all variants of graph
may
use the Hershey fonts, and all variants of graph
except
graph -T hpgl
and graph -T tek
may use the Postscript
fonts. The PCL 5 fonts may be used only by HP-GL Plotters and
graph -T hpgl
.
For the purpose of plotting text strings (see section Text string format and escape sequences), the built-in fonts are divided into typefaces. The 16 Hershey fonts are divided into typefaces as follows.
The three HersheyGothic fonts are singletons: each is font #1 of its own typeface. The two symbol fonts play a special role. By convention, each Hershey typeface contains a symbol font (HersheySerif-Symbol or HersheySans-Symbol, as appropriate) as font #0.
The 35 Postscript fonts are divided into typefaces as follows.
The two Zapf fonts are singletons: each is font #1 of its own typeface. The Symbol font plays a special role. By convention, each Postscript typeface contains the Symbol font as font #0.
The 45 PCL 5 fonts are divided into typefaces as follows.
The ClarendonCondensed, Coronet, Marigold, and Wingdings fonts are singletons: each is font #1 of its own typeface. The Symbol font plays a special role. By convention, each PCL 5 typeface contains the Symbol font as font #0.
As you can see from the three preceding tables, our convention is that in any typeface with more than a single font, font #1 is the normal font, font #2 is italic or oblique, font #3 is bold, and font #4 is bold italic or bold oblique. Additional variants (if any) are numbered #5 and higher.
Of the above built-in fonts, all except for the four Symbol fonts, HersheyCyrillic, HersheyEUC, ZapfDingbats, and Wingdings are ISO-8859-1 fonts. This means that they use the ISO-Latin-1 encoding, which is a superset of ASCII. The four Symbol fonts use a special encoding, since they consist of Greek characters and mathematical symbols. The Symbol encoding and the encoding used by the ZapfDingbats font are documented in the Postscript Language Reference Manual.
The HersheyCyrillic font uses an encoding known as KOI8-R, a superset of ASCII which has become the de facto standard for Unix and networking applications in the former Soviet Union. Insofar as printable ASCII characters go, it is the same as the HersheySerif font. But its `8-bit' characters are different. The byte range 0xc0...0xdf contains lower-case Cyrillic characters and the byte range 0xe0...0xff contains upper case Cyrillic characters. Additional Cyrillic characters are located at 0xa3 and 0xb3. For more on this encoding, see @uref{http://www.nagual.pp.ru/~ache/koi8.html} and the document known as Internet RFC 1489.
The HersheyEUC font is used for displaying Japanese. EUC stands for `extended Unix code', which is a scheme for encoding Japanese, and also other character sets (e.g., Greek and Cyrillic) as multibyte character strings. The format of EUC strings is discussed in Ken Lunde's Understanding Japanese Information Processing (O'Reilly, 1993), which contains much additional information on Japanese text processing. See also @uref{http://www.ora.com/people/authors/lunde/cjk_inf.html, his on-line supplement}.
In the HersheyEUC font, characters in the printable ASCII range,
0x20...0x7e, are similar to US ASCII (they are `JIS Roman',
an ASCII variant standardized by the Japanese Industrial Standards
Committee). Each successive pair of bytes in the
0xa1
...0xfe
range defines a single character in the
JIS X0208 standard. The characters in the JIS X0208 standard include
Japanese syllabic characters (Hiragana and Katakana), ideographic
characters (Kanji), Roman, Greek, and Cyrillic alphabets, punctuation
marks, and miscellaneous symbols. For example, the JIS X0208 standard
indexes the 83 Hiragana as 0x2421
...0x2453
. To
obtain the EUC code for any JIS X0208 character, one adds 0x80
to each byte (i.e., `sets the high bit' on each byte). So the first of
the 83 Hiragana (0x2421
) would be encoded as the successive pair
of bytes 0xa4
and 0xa1
.
The implementation of the JIS X0208 standard in the HersheyEUC font is based on Dr. Hershey's digitizations, and is complete enough to be useful. All Hiragana and Katakana are available, though the little-used `half-width Katakana' are not supported. Also, 603 frequently used Kanji are available. The Hiragana, the Katakana, and the available Kanji all have the same width. The file `kanji.doc', which is distributed along with the GNU plotting utilities, lists the 603 available Kanji. Each JIS X0208 character that is unavailable will be drawn as an `undefined character' glyph (several horizontal lines).
To what extent do the fonts supported by libplot
contain
ligatures? The 35 Postscript fonts and 45 PCL 5 fonts, as
implemented in libplot
, do not contain ligatures. However, four
of the 16 Hershey fonts contain ligatures. The character combinations
"fi", "ff", "fl", "ffi", and "ffl" are automatically drawn as ligatures
in HersheySerif and HersheySerif-Italic. (Also in HersheyCyrillic and
HersheyEUC, since insofar as printable ASCII characters are concerned,
they are identical [or almost identical] to HersheySerif.) In
addition, "tz" and "ch" are ligatures in HersheyGothic-German. The
German double-s character `@ss{'}, which is called an `eszet', is
not regarded as a ligature in any font. To obtain an eszet, you must
either request one with the control sequence "\ss" (see section Text string format and escape sequences), or, if you have an 8-bit keyboard, type an eszet
explicitly.
The preceding discussions dealt with the built-in fonts: the 16 Hershey
fonts, the 35 Postscript fonts, and the 45 PCL 5 fonts. In
fact, the X Plotters supported by libplot
, and graph
-T X
(which is built on top of libplot
) are not restricted to
the built-in fonts. They can display text strings using certain X
Window System fonts as well. Any scalable font which is available
on the current X Window System display, and which has a so-called
XLFD (X Logical Font Description) name, may be used. For example,
the font "-monotype-gill
sans-ultrabold-r-condensed--0-0-0-0-p-0-iso8859-1" is available on some
X displays. It would be referred to as "gill
sans-ultrabold-r-condensed". The command
echo 0 0 1 1 2 0 | graph -T X -F "gill sans-ultrabold-r-condensed"
would draw a plot on an X display, in which all axis ticks are labeled in this font.
You may determine which fonts are available on an X display by using
the xlsfonts
command. Fonts whose names end in
"-0-0-0-0-p-0-iso8859-1" or "-0-0-0-0-m-0-iso8859-1" are scalable
ISO-Latin-1 fonts that may be used by libplot
's X Plotters
and by graph -T X
. The two sorts of font are variable-width and
fixed-width fonts, respectively. Fonts whose names end in
"adobe-fontspecific" may also be used. They are fonts that do not
employ the ISO-Latin-1 encoding.
The escape sequences which allow access to mathematical symbols and Greek characters (see section Text string format and escape sequences) may be employed when using any X Window System font. Also, the escape sequences which allow access to the special non-ASCII characters in any of the built-in ISO-Latin-1 fonts may be employed when using any ISO-Latin-1 X Window System font.
Text strings that are drawn by libplot
, and by such applications
as graph
that are built on libplot
, must consist of
printable characters. No embedded control characters, such as newlines
or carriage returns, are allowed. Technically, a character is
`printable' if it comes from either of the two byte ranges
0x20...0x7e and 0xa0...0xff. The former is the
printable ASCII range.
Text strings may, however, include embedded `escape sequences' that
shift the font, append subscripts or superscripts, or include special
mathematical symbols. As a consequence, the axis labels on a plot
prepared with graph
may include such features.
The format of the escape sequences should look familiar to anyone who is
familiar with the TeX or groff
document formatters. Each
escape sequence consists of three characters: a backslash and two
characters that specify the control code. The most frequently used
escape sequences are as follows.
For example, the string "x\sp2\ep" would be interpreted as `x squared'. Subscripts on subscripts, etc., are allowed. Subscripts and superscripts may be vertically aligned by judicious use of the "\mk" and "\rt" escape sequences. For example, "a\mk\sbi\eb\rt\sp2\ep" produces "a sub i squared", with the exponent `2' placed immediately above the subscript.
There are also escape sequences that switch from font to font within a typeface. For an enumeration of the fonts within each typeface, see section Available text fonts. Suppose for example that the current font is `Times-Roman', which is font #1 in the `Times' typeface. The string "A \f2very\f1 well labeled axis" would be a string in which the word `very' appears in Times-Italic rather than Times-Roman. That is because Times-Italic is the #2 font in the typeface. Font-switching escape sequences are of the form "\fn", where n is the number of the font to be switched to, in the current font. There is currently no support for switching between fonts in different typefaces.
There are also a few escape sequences for horizontal shifts, which are useful for improving horizontal alignment, such as when shifting between fonts. "\r1", "\r2", "\r4", "\r6", "\r8" are escape sequences that shift right by 1 em, 1/2 em, 1/4 em, 1/6 em, and 1/8 em, respectively. "\l1", "\l2", "\l4", "\l6", "\l8" are similar, but shift left instead of right. "A \f2very\r8\f1 well labeled axis" would look better than "A \f2very\f1 well labeled axis".
Square roots are handled with the aid of a special pair of escape sequences, together with the "\mk" and "\rt" sequences discussed above. A square root symbol is begun with "\sr", and continued arbitrarily far to the right with the overbar (`run') escape sequence, "\rn". For example, the string "\sr\mkab\rt\rn\rn" would be plotted as `the square root of ab'. To adjust the length of the overbar, you may need to experiment with the number of times "\rn" appears.
To underline a string, you would use "\ul", the underline escape sequence, one or more times. The "\mk"..."\rt" trick would be employed in the same way. So, for example, "\mkabc\rt\ul\ul\ul" would yield an underlined "ABC". To adjust the length of the underline, you may need to experiment with the number of times "\ul" appears. You may also need to use one or more of the abovementioned horizontal shifts. For example, if the "HersheySerif" font were used, "\mkabc\rt\ul\ul\l8\ul" would yield a better underline than "\mkabc\rt\ul\ul\ul".
Besides the preceding escape sequences, there are also escape sequences for the printable non-ASCII characters in each of the built-in ISO-Latin-1 fonts (which means in every built-in font, except for the symbol fonts, HersheyCyrillic, HersheyEUC, and ZapfDingbats). Such `8-bit' characters, in the 0xa0...0xff byte range, may be included directly in a text string. But if your editor does not permit this, you may use the escape sequences for them instead. The useful non-ASCII characters include accented characters, among others.
There are escape sequences for the mathematical symbols and Greek characters in the symbol fonts, as well. Which font the mathematical symbols and Greek characters are taken from depends on whether your current font is a Hershey font or a Postscript font. The symbols are taken from the HersheySerif-Symbol font or the HersheySans-Symbol font in the former case, and from the Symbol font in the latter.
The following are the escape sequences that provide access to the non-ASCII characters of the current font, provided that it is an ISO-Latin-1 font. Each escape sequence is followed by the position of the corresponding character in the ISO-Latin-1 encoding (in decimal), and the official Postscript name of the character. Most names should be self-explanatory. For example, `eacute' is a lower-case `e', equipped with an acute accent.
The following are the escape sequences that provide access to mathematical symbols and Greek characters in the current symbol font, whether HersheySerif-Symbol or HersheySans-Symbol (for Hershey fonts) or Symbol (for Postscript fonts). Each escape sequence is followed by the position (in octal) of the corresponding character in the symbol encoding, and the official Postscript name of the character. Many escape sequences and names should be self-explanatory. "\*a" represents a lower-case Greek alpha, for example. For a table displaying each of the characters below, see the Postscript Language Reference Manual.
Finally, there are escape sequences that apply only if the current font is a Hershey font. Most of these escape sequences provide access to special symbols that belong to no font, and are accessible by no other means. These symbols are of two sorts: miscellaneous and astronomical. The escape sequences for the miscellaneous symbols are as follows.
The final escape sequence in the table above, "\s-", yields a letter rather than a symbol. It is provided because in some Hershey fonts, the shape of the lower-case letter `s' differs if it is the last letter in a word. This is the case for HersheyGothic-German. The German word "besonders", for example, should be written as "besonder\s-" if it is to be rendered correctly in this font. The same is true for the two Hershey symbol fonts, with their Greek alphabets (in Greek text, lower-case final `s' is different from lower-case non-final `s'). In Hershey fonts where there is no distinction between final and non-final `s', "s" and "\s-" are equivalent.
The escape sequences for the astronomical symbols are listed in the following table. We stress that that like the preceding miscellaneous escape sequences, they apply only if the current font is a Hershey font.
The preceding miscellaneous and astronomical symbols are not the only
special non-font symbols that may be used if the current font is a
Hershey font. The entire library of glyphs digitized by Allen V.
Hershey is built into GNU libplot
. So text strings may
include any Hershey glyph. Each of the 1641 available Hershey glyphs is
identified by a four-digit number. Standard Hershey glyph #1 would
be specified as "\#H0001". The standard Hershey glyphs range from
"\#H0001" to "\#H3999", with a number of gaps. Some additional glyphs
designed by others appear in the "\#H4000"..."\#H4194" range.
Syllabic Japanese characters (Kana) are located in the
"\#H4195"..."\#H4399" range.
You may order a table of nearly all the Hershey glyphs in the "\#H0001"..."\#H3999" range from the U.S. National Technical Information Service, at +1 703 487 4650. Ask for item number PB251845; the current price is about US$40. By way of example, the string
"\#H0744\#H0745\#H0001\#H0002\#H0003\#H0869\#H0907\#H2330\#H2331"
when drawn will display a shamrock, a fleur-de-lys, cartographic (small) letters A, B, C, a bell, a large circle, a treble clef, and a bass clef. Again, this assumes that the current font is a Hershey font.
You may also use Japanese syllabic characters (Hiragana and Katakana)
and ideographic characters (Kanji) when drawing strings in any Hershey
font. In all, 603 Kanji are available; these are the same Kanji
that are available in the HersheyEUC font. The Japanese characters are
indexed according to the JIS X0208 standard for Japanese typography,
which represents each character by a two-byte sequence. Each JIS X0208
character would be specified by an escape sequence which expresses this
two-byte sequence as four hexadecimal digits, such as "\#J357e". Both
bytes must be in the 0x21
...0x7e
range in order to
define a JIS X0208 character. Kanji are located at "\#J3021" and above.
The file `kanji.doc', which is distributed along with the GNU plotting
utilities, lists the available Kanji.
Characters appearing elsewhere in the JIS X0208 encoding may be accessed similarly. For example, Hiragana and Katakana are located in the "\#J2421"..."\#J257e" range, and Roman characters are located in the "\#J2300"..."\#J237e" range. The file `kana.doc' lists the encodings of the Hiragana and Katakana. For more on the JIS X0208 standard, see Ken Lunde's Understanding Japanese Information Processing (O'Reilly, 1993), and @uref{http://www.ora.com/people/authors/lunde/cjk_inf.html, his on-line supplement}.
The Kanji numbering used in A. N. Nelson's Modern Reader's Japanese-English Character Dictionary, a longtime standard, is also supported. (This dictionary is published by C. E. Tuttle and Co., with ISBN 0-8048-0408-7. A revised edition [ISBN 0-8048-2036-8] appeared in 1997, but uses a different numbering.) `Nelson' escape sequences for Kanji are similar to JIS X0208 escape sequences, but use four decimal instead of four hexadecimal digits. The file `kanji.doc' gives the correspondence between the JIS numbering scheme and the Nelson numbering scheme. For example, "\#N0001" is equivalent to "\#J306c". It also gives the positions of the available Kanji in the Unicode encoding.
All available Kanji have the same width, which is the same as that of the syllabic Japanese characters (Hiragana and Katakana). Each Kanji that is not available will print as an `undefined character' glyph (a set of horizontal lines). The same is true for non-Kanji JIS X0208 characters which are not available.
The GNU libplot
library supports a standard set of marker
symbols, numbered 0 through 31. These are the symbols that the
graph
program will plot at each point of a dataset, if the
`-S' option is used. The list is as follows (by convention, marker
symbol #0 means no symbol at all).
The interpretation of marker symbols 1 through 5 is the same as in the GKS (Graphics Kernel System).
Symbols 32 and up are interpreted as characters in a certain text font.
For libplot
, it is the current font. For graph
, it is the
font selected with the `--symbol-font-name' option. By default,
this is the ZapfDingbats font except in graph -T hpgl
and
graph -T tek
. graph -T hpgl
and graph -T tek
currently have no access to Postscript fonts, so they use the
HersheySerif
font instead.
Many of the characters in the ZapfDingbats font are suitable for use as marker symbols. For example, character #74 is the Texas star. Doing
echo 0 0 1 2 2 1 3 2 4 0 | graph -T ps -m 0 -S 74 0.1 > plot.ps
will produce a Postscript plot consisting of five data points, not joined by line segments. Each data point will be marked by a Texas star, of a large font size (0.1 times the width of the plotting box).
Many of the plotting utilities allow colors to be specified by name.
For example, graph
supports the `--frame-color' option.
graph -T hpgl
and plot -T hpgl
check the value of the
HPGL_PENS
environment variable, as do the HP-GL Plotters
available in the libplot
library (on which they are based).
Also, the libplot
library includes the pencolorname and
fillcolorname functions.
In any of these contexts, 665 distinct color names are recognized, including obscure ones like "dark magenta", "forest green", and "olive drab". Color names are case-insensitive, and spaces are ignored. So, for example, "RosyBrown" is equivalent to "rosy brown", and "DarkGoldenrod3" to "dark goldenrod 3".
The file `colors.txt', which is distributed along with the GNU plotting utilities, lists the available color names. They are essentially the color names recognized by recent releases of the X Window System, which on most machines are listed in the file `/usr/lib/X11/rgb.txt'. However, for every color name containing the string "gray", a version containing "grey" has been included. For example, both "dark slate gray 4" and "dark slate grey 4" are recognized color names.
A GNU graphics metafile is produced by raw graph
or by any other
graphics application that uses the Metafile Plotter support contained in
libplot
. It is a sort of audit trail: it contains a
record of which libplot
functions have been called, together with
their arguments. That is, it is a sequence of plotting
commands, each of which may be followed by data. Each plotting command
is an `op code': a single ASCII character, indicating which
libplot
function was called. The data following the command are
the arguments of the function.
There are two sorts of GNU metafile: binary (the default) and portable
(human-readable). If you wish to transfer GNU metafiles between
machines of different types, you should use portable rather than binary
format. Portable metafiles are produced by raw graph
when the
`-O' option is specified, and by the metafile driver of
libplot
when the META_PORTABLE
parameter is set to "yes".
Both binary and portable may be translated to other formats by GNU
plot
. Binary metafiles begin with the magic string #PLOT 1
,
and portable metafiles with the magic string #PLOT 2
.
In the portable format, the arguments (integers, floating point numbers,
or strings) are printed in a human-readable form, separated by spaces,
and each argument list ends with a newline. In the binary format, the
arguments are represented as integers, single precision floating point
numbers, or newline-terminated ASCII strings. The role played by the
newline character as a terminator is acceptable because each
libplot
function includes a maximum of one string among its
arguments, and the string may not include a newline. Moreover, the
string must come last among the arguments.
In the traditional plot(5) format produced by pre-GNU versions of
graph
, command arguments were either two-byte integers or
newline-terminated strings. At the time plot(5) format was
designed, `two-byte integer' was synonymous with `short integer', but
that is no longer the case. GNU plot
can convert metafiles
in the traditional format to GNU metafiles in either binary or portable
format. The absence of a magic string makes it possible to distinguish
files in plot(5) format from GNU metafiles.
The following table lists some of the op codes that appear in either
version of GNU metafile format, i.e., the possible single-character
commands, followed by the name of the libplot
function they
stand for. All 79 basic libplot
functions have a
corresponding op code, with the exception of (1) the setup
functions flushpl
and outfile
, (2) the functions
havecap
, labelwidth
, and flabelwidth
, which return
information, and (3) the pencolorname
and
fillcolorname
functions, which are mapped to pencolor
and
fillcolor
internally.
arc
circle
erase
linemod
line
move
cont
point
space
label
The op codes above are actually the op codes of the traditional plot(5)
format. Since the GNU metafile format is compatible with it, they
are also used in GNU metafiles. The other op codes of metafile
format are too numerous to list. They are defined in the header file
plot.h
, which is distributed along with the plotting utilities.
idraw
The idraw
utility mentioned several times in this documentation
is a freely distributable interactive drawing editor for the X
Window System. It may be used to edit the output of graph -T
ps
, or, in general, the output of any application that uses the
Postscript Plotter support contained in libplot
.
The current version of idraw
is maintained by Vectaport, Inc.,
and is available at @uref{http://www.vectaport.com, their Web site}.
It is part of the ivtools
package, which is a framework for
building custom drawing editors. idraw
was originally part of
the InterViews
package, developed by Stanford University and
Silicon Graphics. The InterViews
package is available at
@uref{ftp://interviews.stanford.edu, a distribution site} but is no
longer supported. Retrieving the ivtools
package instead is
recommended.
Also available at @uref{http://www.vectaport.com, Vectaport's Web site}
is an enhanced version of idraw
called drawtool
. Unlike
idraw
, drawtool
can import bitmapped graphics in
PBM/PGM/PPM, TIFF, and X11 bitmap formats.
xfig
The xfig
utility mentioned several times in this documentation is
a freely distributable interactive drawing editor for the X Window
System. It may be used to edit the output of graph -T fig
,
or in general the output of any application that uses the
Fig Plotter support contained in libplot
.
The current version is available at
@uref{ftp://ftp.x.org/contrib/applications/drawing_tools/}. It can
import graphics in GIF, X11 bitmap, and Postscript formats.
Accompanying the editor is a package called transfig
, which
allows xfig
graphics to be exported in many formats. GIF, X11
bitmap, LaTeX, and Postscript formats are supported.
Several of the GNU plotting utilities were inspired by Unix plotting
utilities. A graph
utility and various plot filters were present
in the first releases of Unix from Bell Laboratories, going at least as
far back as the Version 4 distribution (1973). Most of the work on
tying them together and breaking out device-dependent versions of
libplot
was performed by @email{llc@research.att.com, Lorinda
Cherry}. By the time of Version 7 Unix (1979) and the subsequent
Berkeley releases, the package consisting of graph
, plot
,
spline
, and several device-dependent versions of libplot
was a standard Unix feature. The first display device supported by the
package was a Versatec storage scope. By the early 1980's, supported
devices included Tektronix storage scopes, 200dpi electrostatic
printer/plotters from Versatec and Varian, pen plotters from
Hewlett--Packard, and early graphics terminals.
In 1989, @email{rich@lamprey.utmb.edu, Rich Murphey} wrote the first
GNU versions of graph
, plot
, and spline
, and the
earliest documentation. Richard Stallman further directed development
of the programs and provided editorial support for the documentation.
@email{interran@uluru.stanford.edu, John Interrante}, of the InterViews
team at Stanford, generously provided the idraw
Postscript
prologue now included in libplot
, and helpful comments. The
package as it stood in 1991 was distributed under the name `GNU
graphics'.
In 1995 @email{rsm@math.arizona.edu, Robert Maier} took over
development of the package, and designed and wrote the current,
maximally device-independent, standalone version of libplot
. He
also rewrote graph
from scratch, turning it into a real-time
filter that would use the new library. He fleshed out spline
too, by adding support for splines in tension, periodicity, and cubic
Bessel interpolation.
Most development work on ode
was performed by
@email{nbt@reed.edu, Nick Tufillaro} in 1978--1994, on a sequence of
platforms that extended back to a PDP-11 running Version 4 Unix. In
1997 Robert modified Nick's 1994 version to agree with GNU conventions
on coding and command-line parsing, extended it to support the full set
of special functions supported by gnuplot
, and extended the
exception handling.
Many other people aided the development of the plotting utilities
package along the way. The Hershey vector fonts now in libplot
are of course based on the characters digitized in the mid to late
1960's by Allen V. Hershey. Additional characters and/or marker
symbols were taken from the SLAC Unified Graphics System developed by
Robert C. Beach in the mid-1970's, and from the fonts designed by
@email{wolff@inf.fu-berlin.de, Thomas Wolff} for Ghostscript. The
table-driven parser used in tek2plot
was written at Berkeley in
the mid-1980's by @email{moy@parc.xerox.com, Edward Moy}. Arthur
Smith, formerly of LASSP at Cornell, provided code for his xplot
utility. @email{toy@rtp.ericsson.se, Ray Toy} helped with the tick
mark spacing code in graph
and was the first to incorporate GNU
getopt
. Peter Karnow of URW and @email{turk@apple.com, Ken
Turkowski} of Apple developed the `sagitta' algorithm used in an
extended form in libplot
for drawing circular and elliptic arcs.
@email{beebe@math.utah.edu, Nelson Beebe} exhaustively tested the
package installation process.
Robert Maier wrote the documentation, which now incorporates Nick
Tufillaro's ode
manual. Julie Sussmann checked over the
documentation for style and clarity.
This document was generated on 28 September 1998 using the texi2html translator version 1.51.