3.2 Formatting and Terminals

In this section I shall outline the new and modified commands for controlling the graphic output format of PyXPlot.

The widths of plots may be set be means of two commands – set size and set width. Both are equivalent, and should be followed by the desired width measured in centimetres, for example:

set width 20

The set size command can also be used to set the aspect ratio of plots by following it with the keyword ratio. The number which follows should be the desired ratio of height to width. The following, for example would produce plots three times as high as they are wide:

set size ratio 3.0

The command set size noratio returns to PyXPlot’s default aspect ratio of the golden ratio, i.e. $\left((1+\sqrt {5})/2\right)^{-1}$, which matches that of a sheet of A4 paperOf less practical significance, it has been in use since the time of the Pythagoreans, and is seen repeatedly in the architecture of the Parthenon.. The special command set size square sets the aspect ratio to unity.

If the enlarge modifier is used with the set terminal command then the whole plot is enlarged or, in the case of large plots, shrunk to the current paper size (minus a small margin). The aspect ratio of the plot is preserved. This is perhaps most useful when preparing a plot to send to a printer with the postscript terminal.

In Section 2.6 I described how the set terminal command can be used to produce plots in various graphic formats. In addition, I here describe how the way in which plots are displayed on the screen can be changed. The default terminal, X11, is used to send output to screen.

By default, each time a new plot is generated, if the previous plot is still open on the display, the X11 terminal will replace it with the new one, thus keeping only one plot window open at a time. This has the advantage that the desktop does not become flooded with plot windows.

If this behaviour is not desired, old plots can be kept visible when plotting further graphs by using the the X11_multiwindow terminal:

 
set terminal X11_singlewindow
plot sin(x)
plot cos(x)  <-- first plot window disappears

c.f.:

 
set terminal X11_multiwindow
plot sin(x)
plot cos(x)  <-- first plot window remains

As an additional option, the X11_persist terminal keeps plot windows open after PyXPlot exits; the above two terminals close all plot windows upon exit.

As there are many changes to the options accepted by the set terminal command in comparison to those understood by gnuplot, the syntax of PyXPlot’s command is given below, followed by a list of the recognised settings:

 
set terminal { X11_singlewindow | X11_multiwindow | X11_persist |
               postscript | eps | pdf | gif | png | jpg }
             { colour | color | monochrome }
             { portrait | landscape }
             { invert | noinvert }
             { transparent | solid }
             { enlarge | noenlarge }

x11_singlewindow

Displays plots on the screen (in X11 windows, using ghostview). Each time a new plot is generated, it replaces the old one, preventing the desktop from becoming flooded with old plots.The author is aware of a bug, that this terminal can occasionally go blank when a new plot is generated. This is a known bug in ghostview, and can be worked around by selecting File $\to $ Reload within the ghostview window. [default when running interactively; see below]

x11_multiwindow

As above, but each new plot appears in a new window, and the old plots remain visible. As many plots as may be desired can be left on the desktop simultaneously.

x11_persist

As above, but plot windows remain open after PyXPlot closes.

postscript

Sends output to a postscript file. The filename for this file should be set using set output. [default when running non-interactively; see below]

eps

As above, but produces encapsulated postscript.

pdf

As above, but produces pdf output.

gif

Sends output to a gif image file; as above, the filename should be set using set output.

png

As above, but produces a png image.

jpg

As above, but produces a jpeg image.

colour

Allows datasets to be plotted in colour. Automatically they will be displayed in a series of different colours, or alternatively colours may be specified using the with colour plot modifier (see below). [default]

color

Equivalent to the above; provided for users of nationalities which can’t spell. Uwasy,

monochrome

Opposite to the above; all datasets will be plotted in black.

portrait

Sets plots to be displayed in upright (normal) orientation. [default]

landscape

Opposite of the above; produces side-ways plots. Not very useful when displayed on the screen, but you fit more on a sheet of paper that way around.

invert

Modifier for the gif, png and jpg terminals; produces output with inverted colours.This terminal setting is useful for producing plots to embed in talk slideshows, which often contain bright text on a dark background. It only works when producing bitmapped output, though a similar effect can be achieved in postscript using the set textcolour and set axescolour commands (see Section 3.4.3).

noinvert

Modifier for the gif, png and jpg terminals; opposite to the above. [default]

transparent

Modifier for the gif and png terminals; produces output with a transparent background.

solid

Modifier for the gif and png terminals; opposite to the above. [default]

enlarge

Enlarge or shrink contents to fit the current paper size.

noenlarge

Do not enlarge output; opposite to the above. [default]

The default terminal is normally x11_singlewindow, matching approximately the behaviour of gnuplot. However, there is an exception to this. When PyXPlot is used non-interactively – i.e. one or more command scripts are specified on the command line, and PyXPlot exits as soon as it finishes executing them – the x11_singlewindow is not a very sensible terminal to use. Any plot window would close as soon as PyXPlot exited. The default terminal in this case changes to postscript.

One exception to this is when the special ‘–’ filename is specified in a list of command scripts on the command line, to produce an interactive terminal between running a series of scripts. In this case, PyXPlot detects that the session will be interactive, and defaults to the usual x11_singlewindow terminal.

An additional exception is on machines where the DISPLAY environment variable is not set. In this case, PyXPlot detects that it has access to no X-terminal on which to display plots, and defaults to the postscript terminal.

The gif, png and jpg terminals result in some loss of quality, since the plot has to be sampled into a bitmapped graphic format. By default, this sampling is performed at 300 dpi, though this may be changed using the command set dpi <value>. Alternatively, it may be changed using the DPI option in the settings section of a configuration file (see Section 4.1).