Warning: If making making plots and graphs by typing Postscript commands seems like a good idea to you, you probably need to get out more.
PostScript is a graphics language that can be used to draw text and images. Because PostScript files are plain text, they can easily be created by computer programs like Labview. This lets you bundle data with auxiliary information such as the date, who took the data, or the preamplifier settings and display all of this information on one page. It also can save the time that would be needed to open the data files in a plotting program and generating a plot that is suitable for a report or a publication. The plots generated by writing a postscript file directly can be made so that they are immediately suitable for publications. An essential feature of this approach is that the data is stored with the postscript file as text columns separated by spaces. Storing the data this way makes it possible to copy just this section of the file and paste it into a spreadsheet or commercial plotting program.
A plot file can be divided into three sections. At the top of the file are definitions. These are things like the plot title, the labels for the axes, the ranges for the axes, etc. There may also be information in this section that does not appear in the plot like the date the data was measured. The middle section of the file contains the data to be plotted. The data is arranged in text columns separated by spaces. The third section of the file is the PostScript plotting routine. In this section, PostScript commands are used to generate a plot based on the information specified in the first two sections. Generally you don't have to change the third section. It is just appended to the first two sections. This last section can also be used to add standard content like the logo of your institute.
The following form demonstrates how this works. The title, the x and y axes labels, and the data can be input into the form. When you press the 'Create pdf' button, a pdf file of the plot will be generated.
Here is the same form except this one outputs the eps file. You can see how the eps file is divided into three sections: definitions, data and the plotting engine.
Now we will discuss a more general form that will allow you to choose how many lines will be plotted, the line colors, the line widths, the positions of the plot on the page, etc.
Near the top of an encapsulated postscript (eps) file, the bounding box is specified. This is used to separate essential data (like the plot) from supporting material like the date, the figure number, or a logo. When the eps file is printed separately, the whole page is shown but when it is included in another document only the content within the bounding box will appear. The bounding box is specified at the top of the eps file by four numbers corresponding to the x-coordinate of the lower-left corner, the y-coordinate of the lower-left corner, the x-coordinate of the upper-right corner, and the y-coordinate of the upper-right corner measured in points. A point is 1/72 of an inch. The lower left corner of the page is 0,0. The upper right hand corner of an 8.5 by 11 inch piece of paper is 612, 792. The header of a postscript file would look like this:
%!PS-Adobe-3.0 EPSF-3.0
%%generated by: your program
%%BoundingBox: 0 0 612 792
The number of lines in the plot is specified in postscript like this:
/nlines 3 def % 3 lines in plot
Anything after the % sign is a comment. The next parameter that needs to be specified is the number of columns of data.
/ncol 4 def % 4 columns
The column(s) that will be used as the x-coordinates and the column(s) that will be used as the y-coordinates must be specified. This is done by defining two postscript arrays xcols and ycols. There are as many elements in the array as there are lines. The nth element of xcol specifies the column that will be used as the x-coordinate of the nth line.
For instance,
/xcols [1 1 1] def
/ycols [2 3 4] def
will use the first column as the x-coordinate for all of the lines and the second, third and fourth columns as the y-coordinates of the three lines. The arrays,
/xcols [1 1 3] def
/ycols [1 2 4] def
will plot column 1 against itself (drawing a straight line), plot column 2 vs. column 1 and will plot column 4 vs. column 3. If the parameters ncol, nlines, xcols, ycols, and the data are not consistent, the eps file is likely to crash.
The next definition is an array that defines the linewidths of the lines. There are as many elements of this array as there are lines. The linewidths are specified in points. The linewidths do not have to have an integer value. For instance the specification of the linewidths of three lines might be,
/lnwd [1.33 0.75 2] def
Three arrays are used to specify the colors of the lines. These arrays are called red, green, and blue. There are as many elements in the arrays as there are lines. The colors are specified as numbers between 0 and 1. For instance, the following arrays could be used to specify the colors of six lines.
/red [0 1 0 0 1 0.9] def
/green [0 1 0 1 0.8 0.9] def
/blue [0 1 1 1 0.8 0.9] def
The first line would be black, the second white, the third blue, the fourth cyan, the fifth a pastel red, and the sixth a light gray.
There are four parameters that specify the size of the plot and the position of the lower left corner on the page.
/x1 100 def %left edge of the plot
/y1 400 def %bottom edge of plot
/wp 400 def %width of plot
/hp 280 def %height of plot
These positions are also measured in points. The axes labels are outside the plot so it is important to leave enough room for them.
The plotting range is defined by the four parameters:
/xmin 0 def
/xmax 2 def
/ymin 0 def
/ymax 2 def
These are not measured in points but are the maximum and minimum values of the data that should be plotted.
The title and the labels for the two axes are specified.
/title (title) def
/xlabel (x) def
/ylabel (y) def
The text between the parentheses () will be used. The parentheses themselves will not appear.
Two arrays specify the positions where the tic marks will appear and the text labels for these tic marks. The positions of the tic marks are measured in the same units as the data.
/xtics [0 1] def
/ytics [0 1] def
/xtext [(0) (1)] def
/ytext [(0) (1)] def
Comments can be added around the plot using the arrays,
/comment [(date) (Author: George)] def
/xcomment [450 100] def
/ycomment [720 250] def
The first array contains the text of the comment and the next two arrays contain the x and y positions of the comment measured in points.
Finally the data must be entered into the postscript file. This is also a postscript array called ary. Its definition looks like this with the data arranged in text columns separated by spaces.
/ary [
0 0 0 0
0.5 0.1 1.5 1.3
1 1 0.3 1.7
1.5 1 1 1.8
2 1.1 0.6 2
] def
The following form will allow you to specify all of these parameters. And then will append the postscript routine that does the actual plotting to form a complete eps file.
Here is the same form except this one generates a pdf file so you can see how the plot looks.