\chapter[GNUPLOT: Plotting Functions]%
{GNUPLOT: Display of functions and surfaces}
\label{GNUPLOT}
\typeout{{GNUPLOT: Display of functions and surfaces}}
{\footnotesize
\begin{center}
Herbert Melenk \\
Konrad--Zuse--Zentrum f\"ur Informationstechnik Berlin \\
Takustra\"se 7 \\
D--14195 Berlin--Dahlem, Germany \\[0.05in]
e--mail: melenk@zib.de
\end{center}
}
\ttindex{GNUPLOT}
The {\bf gnuplot} system provides easy to use graphics output for
curves or surfaces which are defined by formulas and/or data sets.
The \REDUCE\ GNUPLOT package lets one use the GNUPLOT graphical output
directly from inside \REDUCE, either for the interactive display of
curves/surfaces or for the production of pictures on paper.
For a full understanding of use of the \REDUCE\ GNUPLOT package it is
best to be familiar with {\bf gnuplot}.
The main command is {\tt PLOT}\ttindex{PLOT}. It accepts an arbitrary
list of arguments which are either an expression to be plotted, a
range expressions or an option.
\begin{verbatim}
load_package gnuplot;
plot(w=sin(a),a=(0 .. 10),xlabel="angle",ylabel="sine");
\end{verbatim}
The expression can be in one or two unknowns, or a list of two
functions for the x and y values. It can also be an implicit equation
in 2-dimensional space.
\begin{verbatim}
plot(x**3+x*y**3-9x=0);
\end{verbatim}
The dependent and independent variables can be limited to a range with
the syntax shown in the first example. If omitted the independent
variables range from -10 to 10 and the dependent variable is limited
only by the precision of the IEEE floating point arithmetic.
There are a great deal of options, either as keywords or as
{\tt variable=string}. Options include:
{\tt title}\ttindex{title}: assign a heading (default: empty)
{\tt xlabel}\ttindex{xlabel}: set label for the x axis
{\tt ylabel}\ttindex{ylabel}: set label for the y axis
{\tt zlabel}\ttindex{zlabel}: set label for the z axis
{\tt terminal}\ttindex{terminal}: select an output device
{\tt size}\ttindex{size}: rescale the picture
{\tt view}\ttindex{view}: set a viewpoint
{\tt (no)}{\tt contour}\ttindex{contour}: 3d: add contour lines
{\tt (no)}{\tt surface}\ttindex{surface}: 3d: draw surface (default: yes)
{\tt (no)}{\tt hidden3d}\ttindex{hidden3d}: 3d: remove hidden lines (default: no)
The command {\tt PLOTRESET}\ttindex{PLOTRESET} closes the current
GNUPLOT windows. The next call to {\tt PLOT} will create a new
one.
GNUPLOT is controlled by a number of switches.
Normally all intermediate data sets are deleted after terminating
a plot session. If the switch {\tt PLOTKEEP}\ttindex{PLOTKEEP} is set on,
the data sets are kept for eventual post processing independent
of \REDUCE.
In general {\tt PLOT} tries to generate smooth pictures by evaluating
the functions at interior points until the distances are fine enough.
This can require a lot of computing time if the single function
evaluation is expensive. The refinement is controlled by the switch
{\tt PLOTREFINE}\ttindex{PLOTREFINE} which is on by default. When you
turn it off the functions will be evaluated only at the basic points.
The integer value of the global variable {\tt
PLOT\_XMESH}\ttindex{PLOT\_XMESH} defines the number of initial
function evaluations in x direction for \f{PLOT}. For 2d graphs
additional points will be used as long as {\tt
plotrefine}\ttindex{plotrefine} is on. For 3d graphs this number
defines also the number of mesh lines orthogonal to the x axis. {\tt
PLOT\_YMESH}\ttindex{PLOT\_YMESH} defines for 3d plots the number of
function evaluations in the y direction and the number of mesh lines
orthogonal to the y axis.
The grid for localising an implicitly defined curve in \f{PLOT}
consists of triangles. These are computed initially equally
distributed over the x-y plane controlled by {\tt PLOT\_XMESH}. The
grid is refined adaptively in several levels. The final grid can be
visualised by setting on the switch {\tt
SHOW\_GRID}\ttindex{SHOW\_GRID}.