After going through the previous sections, you probably would like to get your plots printed on paper or imported into your document. In this section you will learn some of the ways to accomplish these tasks.
gnuplot has support for a rather large variety of printers. To see the
list of supported printers (and other graphic formats), type set
term at the gnuplot command line. The command set term
term-type
tells gnuplot that the subsequent plots are to be
generated on
term-type
. If you are using a Laserjet II
compatible printer, you can use hpljii
. If you are printing on a PostScript printer, you
can use postscript. There are options for controlling the
orientation, fonts, font sizes, etc. For the details,
check the online help or the gnuplot manual.
Once you have set the terminal type to the correct device, you need to tell
gnuplot where you want to send the output. This is done by set
output ` filename
', where
filename
is the name of file where
the plot is to be stored. On Unix systems, you can do set term `|
lpr -Php1' to send the plot directly to the printer (the -Php1
is the lpr option for selecting the printer). However, the plot
won't be printed until you exit gnuplot.
Here is an example for plotting the function
to the file
bivnorm.ps and then printing it out:
f(x,y)=exp(-.5*(x**2+y**2))/(2*pi) set title 'Bivariate Normal Density' set xlabel 'x' set ylabel 'y' splot [-4:4] [-4:4] f(x,y) # check the plot on screen set term post # set terminal type to postscript set output 'bivnorm.ps' # set the output file to bivnorm.ps replot # regenerate last plot set term x11 # reset terminal type to the screen !lpr -Php1 bivnorm.psThe last line starts with !, which tells gnuplot that what follows is a system command. If you are on a PC and want to generate the plot to the Laserjet format, the last five lines can be replaced by
set term hpljii 150 # set terminal type to Laserjet II set output 'bivnorm.hp' # set the output file to bivnorm.hp replot # regenerate last plot set term vgalib # reset terminal type to the screen !copy bivnorm.hp prn /bIf you want the plot to be printed directly to the printer, use prn instead of a filename in the set term command. Just typing set output without any argument sets output to standard output.
If you want to generate several plots in the same file, you can use the clear command to tell gnuplot to go to a new page. If you set terminal to a screen device, the clear command will clear the graphics screen/window.
There are several ways to put multiple plots on the same page, none of
which is trivial. If you are using a word processor or desktop publishing
program that can import one of the graphics formats supported by gnuplot,
(e.g. pbm, eps, aifm, hpgl, dxf, etc.)
this should not be a problem. If you are using dvips to produce
TeX/LaTeX output, you can use the psfig macros to put multiple
PostScript files on the same page. If you are using LaTeX, the instructions
in Section should help you achieve this.
Figure: This the example plot generated with the latex terminal
type in gnuplot.
There is a latex terminal type in gnuplot, which lets you generate plots in LaTeX's picture environment format. Here's an example:
f(x)=sin(exp(x**2)) g(x)=cos(exp(x**2)) set term latex set samples 500 set output 'example.tex' set title 'An Example of Plotting in \LaTeX\ with {\sf gnuplot}' set format y '$%g$' set xtics ('$-\frac{\pi}{2}$' -pi/2, '$-\frac{\pi}{4}$' -pi/4,\ '0' 0, '$\frac{\pi}{4}$' pi/4, '$\frac{\pi}{2}$' pi/2) set xrange[-pi/2:pi/2] plot f(x) title '$\sin e^{x^2}$', g(x) title '$\cos e^{x^2}$'Then in the LaTeX document, where you want to insert the plot, do the following:
\begin{figure} \begin{center} \end{center} \caption{This the example plot generated with the \cmd{latex} terminal type in {\sf gnuplot}.} \end{figure}You should get the plot shown in Figure
Note that the number of points to be evaluated is set to 500. This is done to improve the appearance of the curves on paper. gnuplot's default setting of 100 points may be sufficient for viewing on the screen, but the resolutions of printers are usually much higher than that of screen.
For more details, please refer to the document LaTeX and the GNUPLOT Plotting Program by David Kotz, which is included with the gnuplot\ distribution.
If you are using a PostScript device for LaTeX output, there is a
pslatex terminal type, which uses LaTeX to typeset the title, labels, etc.
and PostScript specials for the plot. The quality of the plot
is better than the plain LaTeX's native picture environment. The output
from gnuplot with the pslatex terminal type can be inserted into
your LaTeX document the same way as described above. However, most
dvi previewers don't support the PostScript specials. Thus you won't be
able to preview the plot with the rest of the document.
There are a few drawbacks of using the latex terminal type.
For one, the plot is drawn with commands in LaTeX's picture
environment. Lines can only be drawn in certain slopes. Thus the appearance
of the plot can be less than satisfying. For another, it is almost
impossible to import a three-dimensional surface plot into LaTeX with it
because it will almost always exceed LaTeX's capacity. Using
pslatex instead of latex usually doesn't help.
An alternative is the eepic terminal type.
eepic is an extended picture environment for LaTeX. Figure
was created with the eepic terminal type. To use eepic,
you need the files epic.sty and eepic.sty (available
from any Comprehensive TeX Archive Network sites, e.g.,
pip.shsu.edu). You need to load these two style files as options in
the documentstyle statement.
Then you can import the output from gnuplot as described above.