next up previous contents index
Next: How to get and install plt Up: plt Tutorial and Cookbook Previous: On-Screen Plots


Scripting with plt

Using shell scripts (batch files), it is possible to automate the process of making many similar plots using plt. This appendix briefly illustrates how plt can be used in scripts. General techniques for writing shell scripts are well beyond the scope of this book. (There are other books devoted to this subject; choose one that describes your shell, such as the O'Reilly book Learning the bash shell, by Newham and Rosenblatt. If you use MS-Windows, install the bash shell, included in the free Cygwin toolkit available from http://www.cygwin.com/. If you don't know what a shell is, begin by reading an introductory book on Unix or Linux.)

Often it is useful to preview a plot on-screen before (or instead of) producing a printed copy. Writing a script makes it easy to do this. For example, we might create a script named foo, to produce figure 7.5:

#! /bin/sh

plt $* -wm 0 -t "This is the main title for the plot"
plt $* example11.data 0 1 -wm 1 -t "Window 1"

The file foo containing this script should be put in a directory in your PATH, and should be marked as executable using the command:

chmod +x foo

When you run this script, any command-line arguments you give to foo are passed to plt (the shell replaces ``$*'' with these arguments). Thus the command ``foo'' runs plt with no arguments other than those listed above, but the command ``foo -T lw'' runs the same plt commands with the additional arguments ``-T lw''. The output in the second case will be a stream of PostScript code; to print the plot, pipe the output to lwcat, as in:

foo -T lw | lwcat

plt provides the -dev option to allow you to specify options to be processed only if a specific device type is being used for output. The -dev option can be useful in scripts, since it permits you to choose different options for screen plots and printed plots (for example, you might want to use color in screen plots and shades of grey in printed plots). The syntax is:

-dev device "options ..."
The value of device can be either ``lw'' (for PostScript output) or ``xw'' (for X11 output). Following device should be a quoted string containing one or more options (with initial hyphens omitted, as in -F format strings). These options will have effect only if the same device is selected for output (by using -T device or by setting the value of the environment variable PTERM equal to device).

For example, consider this variant of the script above:

#! /bin/sh

plt $* -wm 0 -dev lw -t "This is the main title for the plot"
plt $* example11.data 0 1 -wm 1 -dev lw "sf p G.5" \
 -dev xw "sf p Cred"

If this script is run without any arguments (or with the arguments ``-T xw''), the plot appears in an X11 window with the data in red; if it is run with the arguments ``-T lw'', and the output is piped to lwcat, the plot is printed with the data in 50% grey.


next up previous contents index
Next: How to get and install plt Up: plt Tutorial and Cookbook Previous: On-Screen Plots
George B. Moody (george@mit.edu)
2005-04-26