3.11 Directing where output goes

By default, when Pyxplot is used interactively, all plots are displayed on the screen. It is also possible to produce PostScript output, to be read into other programs or embedded into latex documents, as well as a variety of other graphical formats such as jpeg and png. The set terminal command1 is used to specify the output format that is required, and the set output command is used to specify the file to which output should be directed. For example,

set terminal pdf
set output 'myplot.pdf'
plot 'datafile.dat'

would output a PDF plot of data from the file datafile.dat to the file myplot.pdf, which could be opened in Adobe Reader.

The set terminal command can also be used to configure various output options within each supported file format. For example, the following commands would produce black-and-white or color output respectively:

set terminal monochrome
set terminal color

The former is useful for preparing plots for black-and-white publications, the latter for preparing plots for colorful presentations.

Both PostScript and Encapsulated PostScript can be produced. The former is recommended for producing figures to embed into documents, the latter for plots which are to be printed without further processing. The postscript terminal produces the latter; the eps terminal should be used to produce the former. Similarly the pdf terminal produces files in the Portable Document Format (PDF) read by Adobe Acrobat:

set terminal postscript
set terminal eps
set terminal pdf

It is also possible to produce plots in the gif, png and jpeg graphic formats, as follows:

set terminal gif
set terminal png
set terminal jpg

More than one of the above keywords can be combined on a single line, for example:

set terminal postscript color
set terminal gif monochrome

To return to the default state of displaying plots on screen, the x11 terminal should be selected:

set terminal x11

After changing terminals, the refresh command2 is especially useful; it reproduces the last plot to have been generated in the newly-selected graphical format. For more details of the set terminal command, including how to produce gif and png images with transparent backgrounds, see Chapter 9.

Footnotes

  1. Gnuplot users should note that the syntax of the set terminal command in Pyxplot is somewhat different from that used by Gnuplot; see Section 9.1.
  2. The effect of the refresh command is very similar to that of the replot command with no arguments. The latter simply repeats the last plot command. We will see in Chapter 10 that the refresh command is to be preferred in the current context because it is applicable to vector graphics as well as to graphs.