You have already seen the basic plotting commands in Section .
In this section, you will learn how to create several different kinds of plots
with *gnuplot*.

*gnuplot* can create two types of two-dimensional plots. The first is the usual
*y*=*f*(*x*) in Cartesian coordinates or in polar coordinates.
The other type is a *parametric curve*
(*e.g.* ). Plotting *y*=*f*(*x*) should be a trivial
task after going through the previous sections. To plot
in polar coordinates, you first tell *gnuplot* to switch to polar coordinates
by the command `set polar`. The syntax for plotting
functions in the polar coordinates is exactly the same as that for
Cartesian coordinates, except that `x` is the angle and the value
of the function is the radius. For example, to plot the function
, you can do the following:

set polar plot 1/cos(x)Note that the default unit for the angle is radians. You can change the unit to degrees by

set dummy theta plot 1/cos(theta)

To switch back to Cartesian coordinates, use the command `set nopolar`.

Parametric curves are very handy. If you define the *x*- and
*y*-coordinates as functions of a dummy variable, *t*, you
can plot things like circles, ellipses, and other curves that cannot be
expressed in the functional form *y*=*f*(*x*). Try the following examples:

set parametric plot sin(t), cos(t) plot 3*sin(t-3), 2*cos(t+2), cos(3*t), sin(2*t) set noparametricThe first command tells

You can also plot parametric curves in polar coordinates. In
this case you define *r*=*r*(*t*) and .
Try the following:

set parametric; set polar plot sin(t),cos(t)Did you guess what the curve will look like?

In `parametric polar` mode, `rrange` sets the distance from the
origin to the edge, `xrange` sets the angle, and `yrange` sets
the extent of the plot, which will be square. For instance, try:

set parametric; set polar set rrange [-1:1]; set yrange [-2:2] plot t,0

Note that under `parametric` mode, the range of *t* can be
specified by the `set trange` command. The syntax is the same as
`set xrange`.

You can set the number of points where each function is to be
evaluated by the command `set samples`. For example:

set samples 100; plot f(x) set xrange [0:-10]; set samples 11; plot g(x)The first example tells

By now you have noticed that each function is listed in the key in the upper
right-hand corner of the plot. Perhaps you'd like to specify a title other
than the one *gnuplot* gives you by default. The
option is simply `title '` *curve-name* `'`. Similarly you
can control how the curve is shown by adding the option `with`
*style* where *style* can be `lines`, `points`,
`impulses`, etc. The *gnuplot* manual has the complete list. If you have
several curves on your plot and they are plotted with the same style,
*gnuplot* has several versions of each style which it cycles through.
You can override its selections by adding the integral style codes (line,
then point) after `with` *style* . (You can see all of the
available options by entering the command `test`.) Try

set samples n+1; set xrange [0:n] mu=5; n=15; p=0.4 i(x)=int(x+.1) pd(x)=mu**x*exp(-mu)/i(x)! bd(x)=n!/(i(x)!*(n-i(x))!)*p**x*(1-p)**(n-x) plot bd(x) title 'binomial distribution, p=0.4' with linespoints,\ pd(x) title 'Poisson distribution, mu=5' with impulsesYou can leave a function out of the key entirely by replacing

If you want to plot a bargraph, use
`with boxes`. The width of the bars are controlled by the `set
boxwidth` command. Without any argument, `set boxwidth` tells
*gnuplot* to calculate the width so that successive bars are adjacent to each
other (as in a histogram).

For three-dimensional plots, *gnuplot* supports only Cartesian
coordinates. Therefore you can only plot surfaces of the
type *z*=*f*(*x*,*y*) or . Try the
following:

set hidden3d f(x,y)=x**2+x*y-y**2 splot f(x,y) set parametric splot u-v**2, u**2*v, exp(v) set noparametricThe command

*gnuplot* can generate contour lines
on the *xy*-plane, on the surface itself, or both. The command is
`set contour place `, where

set cntrparam levels auto 5 # set 5 automatic levels set cntrparam levels incr 0,.1,1 # 11 levels from 0 to 1 set cntrparam levels disc .1,.2,.4,.8 # 4 discrete levelsPlease refer to the online help or the

Note that on a color output device, contour lines at different levels are
drawn with different colors. On a monochrome display or non-color printer,
they are shown in different line styles. Also note that if you specify
contours on the surface and turn on the hidden-line removal, the contour
lines will not be shown. This is because contour lines are drawn
``underneath'' the surface, not on top of the surface. You can specify
`set nosurface` to plot only the contour lines.

*gnuplot* cannot generate a contour plot from parametric functions.

The number of values of each coordinate for which the function is
evaluated (and hence the number of lines
on the surface) is set by the command `set isosamples x-number ,
y-number `, where

Sometimes you may want to look at the three-dimensional surface plot from
another direction. This is accomplished by the `set view` command.
The first number following `set view` changes the rotation angle
around the *x*-axis and the second changes the rotation around the *z*-axis.
The default view is 60 degrees about the *x*-axis and 30
degrees about the *z*-axis. For example, try

set xlabel 'x'; set ylabel 'y' splot [0:1] [0,1] x**2*y*(1-y) set view 15,75 replotTry a few other rotations.

You can make a two-dimensional contour map of a surface by using the settings

set nosurface set contour set view 0,0 replotbut the

*gnuplot* can produce plots from tabulated data.
In this section, you will see how
to handle different kinds of data with *gnuplot*. Note that you can put
comments in a data file the same way you can in a *gnuplot* script file;
*gnuplot* ignores everything on the line after the `#` symbol.

The essential rule of data organization is that *gnuplot* reads
one data point per line.

Perhaps the simplest data to plot are a series. Suppose you have
the data for a variable stored in a column in a plain text file. The
command `plot ' data-filename '` will plot the values of
the variable as the

If your data really are a time series, you may want a plot where the
*x*-axis is either the day-of-the-week or the month. The commands
`set xdtics` and `set xmtics` will do these for you.
For `xdtics`, 0 is treated as Sunday, 1 as Monday
and so on. Numbers larger than 6 are converted modulo 7. For `
xmtics`, 1 is treated as January, 2 as February and so on. Numbers
larger than 12 are converted modulo 12 plus 1.

You can also plot series from a bivariate data set. In this case the
first column in the data file is taken as the *x*-coordinate and the
second column is taken as the *y*-coordinate. This allows you to plot
data with scattered *x*'s or series data with a variable step size.

The data file can have many columns. You can tell *gnuplot* which columns
to plot by the `using` keyword following `' data-filename '`
on the

plot 'reg.dat' using 1:2 plot 'reg.dat' using 2:3, 'reg.dat' using 2:6,\ 'reg.dat' using 8:4 with linesThe first command plots the first column in the file as

With the `using` option, you can now plot data directly from labeled
tables prepared by some other program, as long as you remember to put the
`#` at the beginning of each heading line.

When you plot a data set with style `lines`, a null line (a line of zero
length - not a line of spaces) in the data file breaks the line in the plot.

If you wish to put error bars on your plotted data, you need to give *gnuplot*
the error data in either a three-column (*x*, *y*, ) or a four-column
(*x*, *y*, , ) format. You
then specify `with errorbars`.
There is also a style `boxerrorbars`, which requires a fifth column of
data containing the box width.

If you want to have control over the width of the bars in a bar graph, the
bar width data must be in the fifth column of the data file (or the fifth
item in the `using` list, *e.g.* `using 1:2:2:2:3` for a
three-column file) or defined by the command `set boxwidth`.

If you have lots of data and only want to put error bars on some of them,
there is no way to do so directly in *gnuplot*. You'll need to make a
separate file with the subset, or you could edit the data file, setting
the errors to zero for those points to be plotted without error bars.
If you're running under Unix, you could use a filter like `awk` to
do the same thing.

One nice feature of *gnuplot* is that it can transform the *y* values of the
data with the `thru` option of the `plot` command. For example,

plot 'reg.dat' thru sqrt(x)produces the same plot as the first example above, except that the

If you are interested in fitting a curve to a set of *x*-*y* data, there
are several programs (`fudgit` and `gnufit`, for example) that
perform nonlinear least squares fits. Each of these couples easily to
*gnuplot*. If you are looking for more extensive features, check out Octave
(available for Unix only). Octave is a Matlab-like program that performs
many numerical computations. It uses *gnuplot* as its plotting tool. Thus
you can do curve fitting to your data and then pass the result to *gnuplot*\
from Octave, for instance.

You can create three-dimensional scatter plots as easily as two-dimensional
ones. Suppose the data
file `3d.dat` contains five columns of numerical data. The commands

splot '3d.dat' splot '3d.dat' using 1:4:3first plot the points (

The file `3d.dat` can even contain more than one set of data. If you
separate the sets with two null lines, *gnuplot* will refer to the first set as
`index 0`, the second as `index 1`, and so on. You tell *gnuplot*\
which one to plot by placing `index` and the number immediately
after *data-filename* . (It is a pity that `plot` doesn't
have this option, too.)

If you want to make a contour plot from a three-dimensional data set, the
number of `isosamples` is set by the data. Your data set must be
organized as rasters, ,

x(1) y(1) z(1,1) x(1) y(2) z(1,2) x(1) y(3) z(1,3)

x(2) y(1) z(2,1) x(2) y(2) z(2,2) x(2) y(3) z(2,3)

and so on. Each raster of constant *x*-index is terminated by a null line.
(The data can be a single column of *z*'s, but the null lines will
still be needed.) There must be the same number of points in each
raster, but the *x* and *y* values don't have to be the same!

If you have data that are not defined in the tidy grid fashion shown
above and you want to draw contours anyway, *gnuplot* has a command
`set dgrid3d` which does the necessary interpolations for you.

The options on the `plot` and `splot` commands are order-dependent.
The proper sequences are

plot ranges data-file thru using title style plot ranges functions title style splot ranges data-file index using title style splot ranges functions title stylewhere we have listed only the options for clarity.

In this section you will see how your plots can be customized further
with the `set` command.

Note that you can check the settings of all the options that the command
`set` controls by the `show` command. For example, to check the
current *x* range, use the command `show xrange`.

`set logscale` makes the specified axis logarithmic. It takes one
or two arguments. The first argument can be `x, y, xy,` or `
z`. The second argument specifies the base of the logarithms and is
optional (the default is base 10). `set nologscale` turns off logarithmic
scaling.

`set zeroaxis` causes the *x*- and *y*-axes to be plotted, if the
plotting range contains either axis. `set nozeroaxis` turns off
plotting of the axes. The commands `set xzeroaxis`, `set yzeroaxis`,
`set noxzeroaxis` and `set noyzeroaxis` work similarly.

`set key` tells *gnuplot* where to put the legend of the plot. For a
two-dimensional plot, `set key x,y` says to put the legend at
the point (

`set label` lets you add text to the plot. For example,

set label 1 'Max' at .5, 2.3 center set label 2 'Min' at 1.3, -.3 right set label 2 at 1.3, .3put the text ``Max'' centered at the point (0.5,2.3), and the text ``Min'' right-justified at the point (1.3,-0.3). The number after the keyword

`set arrow` can be used to draw arrows or line segments in a plot.
For example,

set arrow 1 from 1,2 to -.5,3 set arrow 2 to 4,4 noheadThe first command draws an arrow from the point (1,2) to the point (-0.5,3). The second command draws a line segment (no arrow head) from the origin (since the

`set grid` causes grid lines to be drawn (in dotted lines) on
the plot. For a three-dimensional surface plot, the grid lines are drawn
at the base of the plot. `set nogrid` turns off the grid lines.

`set border` causes a box to be drawn around the plot (the default
setting). To get rid of the box, use `set noborder`.

`set data options ` and

set data style points set function style lines plot f1(x),f2(x),'data1','data2'would produce a plot with lines (one solid, one dashed) representing the functions and and with two different symbols representing the data in the two files.

`set tics` takes one argument: either `in` or `out`. This
indicates whether the tic marks are to be plotted inside the box or
outside the box.

`set xtics` gives you control over which *x*-values are to be given
tic marks and how these are to be labeled. There are two syntaxes:

set xtics 0,.5,10 set xtics ('5' 1, ' ' 2, 'Hi, Mom' 4)The first example will produce labeled tics at 0, .5, 1, 1.5, ..., 9.5, 10. The second will produce three tic marks, one of which will be unlabeled. If no label is specified, the tic mark will be labeled with its

`set ticslevel` sets the ``height'' of the surface when doing `
splot`. `set tickslevel 0` causes the surface to be drawn from the
base. Giving a positive argument to `set ticslevel` ``elevates'' the
surface. Negative arguments are not allowed.

`set size height , width ` changes the size of the plot. The
argument

The `pause` command is useful when you are creating several
plots with a script file and viewing them on the screen. The commands

plot f(x) pause -1 'Hit <return> for next plot' plot g(x)plot

Tue Jul 16 23:20:34 CDT 1996