Plotting with TEXGraph

Andrew D. Lewis andrew@mast.queensu.ca

18 March 1998

1 Introduction

For me, it is always difficult to get the various plotting programs to make PostScript output look like I want. This inspired me to make a write a program which takes as input a column pairs of numbers and plots them in a way which allows the user the freedom to label the plot as they wish. Since I had the pshacks package already made, I designed my plotting program around this. The result is summarised as follows:

1. The user must supply a file with a column where each line contains two numbers.

2. This file is converted by TEXGraph into a TEX file which contains the pshacks commands for plotting the points in the file.

3. The user may then add the axes, labels, and anything else that seems appropriate.

4. When running TEXGraph, you will be asked for plot limits. Any points which are read in and are outside these limits will not be plotted.

5. TEXGraph will also ask you for the dimensions of the plot.

Of course you must learn how to use pshacks to use TEXGraph to its fullest extent.

With the TEXGraph setup you should have the directories demo, doc, and

pshacks.

2 Setting up TEXGraph^{1}

To install TEXGraph, modify the Makefile so that the BINDIR and MANDIR directories are properly named. Also set PERL to the location of Perl on your system, and DOCDIR so the name of the L^{A}TEX documentation file (with full path). The variable STYLEDIR is the location of the pshacks style file. Now type make to set up the files, make install to install the executable in BINDIR. Typing make man will also install a copy of the man page in MANDIR.

1This set up procedure has been performed with SunOS 5.4 and is not guaranteed to work on any other operating system.

If you do not have sed you will have to make the changes to the files your-

self. First copy texgraph.script to texgraph and texgraph.man to texgraph.

Then look through these two new files for the string %% as this marks spots where replacing needs to be done. Hopefully it will be obvious what changes need to be made.

If you do not already have pshacks installed, go to its directory and follow the instructions in the 00readme.txt file.

3 Using TEXGraph

It is fairly straightforward to use TEXGraph to convert a data file to a file of pshacks commands. If your data is in a file filename.dat type

    texgraph filename[.dat].

If the argument is omitted, the data will be read from standard input and output will be piped to standard output. If the argument is present, the data will be read from the file filename.dat. Then, if a file filename.tginp is present, the input data will be read from it. If this file is not present, the existence of the file tginp.tginp will be checked. If this file is present, the input data will be read from it, and if is is not present, you must enter the input data by hand. The input data consists of the following information:

1. First you will be asked to enter the minimum value for the x-axis on your plot. For reference, the minimum x value which was read in is presented. If you enter the unlikely value 10007.0, TEXGraph will assume you meant the read in minimum value. (This is useful for using files to enter the plot parameters to TEXGraph.)

2. Then you will be asked to enter the maximum value for the x-axis. If you enter the unlikely value of −10007.0, TEXGraph will assume you meant to enter the read in maximum value.

3. Next you do the same thing for the y-axis. It should be noted that any data points which are read in and are not within these specified limits will not be plotted. The same remarks for the values 10007.0 and −10007.0 for the minimum and maximum hold as for the x-axis limits.

4. Now you must decide if you want the axes to have the same scale. If you choose their scale to be the same, you must decide which of the x or y axes will have its length specified. The others dimension will be determined by the scale.

5. If you have not asked that the axes be the same scale, you are now asked whether you want the axis dimension scaled to the Golden Ratio. If you choose this, TEXGraph asks you if you want a short graph or a tall one. You then enter the length of the longer axis.

6. If you choose to specify both axes lengths you now do so. This specifies the size of the square on the page which is represented by the plot limits you entered above.

7. You will now be asked to enter some data about how the plot will be constructed. First you are asked whether you want the points on the plot to be connected. If you choose to not have the points connected, at each point on the plot the TEX command \graphsymbol is executed. This command is not defined by TEXGraph, so you must define it before you read the file of pshacks commands created by TEXGraph.

8. If you chose to connect the points, TEXGraph will next ask you if you want arrows in the graph. You may then choose the spacing and the direction of the arrows. This is useful for making phase portraits.

9. If you chose to connect the points, TEXGraph will next ask you if you want symbols at each point. You may then choose the spacing of the symbols. This is useful for making a plot with several curves where each is distinguished by its symbol. Again the symbol is specified by \graphsymbol.

When you have done all this, TEXGraph builds the files filename.tex, which contains the pshacks commands, and filename.tglog which is a log of the choices you made when creating the plot. No log file is created if the data was sent to standard output.

If you were to type

\begin{pspicture}(x_{0},y_{0})(x_{1},y_{1})
\input{filename}
\end{pspicture}

you would then get a plot of the data points in filename.dat which were in the bounds you specified when you ran TEXGraph. If necessary, the definition of \graphsymbol would be make before you read in filename.tex.

4 Completing the plot

Typically one would like to place axes, ticks, labels, and whatever else on a plot. With the file filename.tex read in, you may use normal pshacks commands to do this. For convenience some commands are defined so that you can perform operations by specifying graph coordinates rather than coordinates on the

page. The commands of this ilk are \grmove, \grrelmove, \grvec, \grrelvec,

\grpavec, and \grrelpavec. These commands behave exactly like the corresponding pshacks commands with the gr removed except that the arguments are in graph coordinates.

If you wish to use any of these commands before you read in filename.tex, you will get an error saying some macros are undefined. These macros are defined at the beginning of filename.tex and you may simply put them in your file by hand if you need to. Simply copy the lines which look like

    \gdef\xscale{xscale}
    \gdef\yscale{yscale}
    \gdef\xoff{xoff }
    \gdef\yoff{yoff }

5 An Example

As an example of how you may add axes to your plot, we consider an example. The file sine.dat in the demo directory contains the data for the graph of a sine wave. First we type

    texgraph sine

We then answer the questions posed by TEXGraph. We ask the plot range in x to be from 0 to 6.2832 ≃ 2π and the plot range in y to be from −1.1 to 1.1. The dimensions of the plot are chosen to be 10cm×5cm. The points are connected and symbols are placed every 20 points. This creates the files sine.tex and sine.tglog. Now we type the commands

\begin{center}
\begin{pspicture}(0,-1.2)(10,6)
\def\graphsymbol{\htext{$\ast$}}
% Data
\input{sine}
\move(0,0)
% Box around plot
\grvec(0,1.1)\grrelvec(6.2832,0)\grvec(6.2832,-1.1)\vec(0,0)
% Line for y=0
\grmove(0,0)\grvec(6.2832,0)
% Ticks
\def\tick#1{\begin{segment}\rvec{0.2}{90}\end{segment}
  \begin{segment}\rmove{0.2}{-90}\htext[t]{#1}\end{segment}
  \relmove(2.5,0)}
\move(0,0)
\tick{$0$}\tick{$\frac{\pi}{2}$}\tick{$\pi$}
\tick{$\frac{3\pi}{2}$}\tick{$2\pi$}
\def\tick#1{\begin{segment}\rvec{0.2}{0}\end{segment}
  \begin{segment}\rmove{0.2}{180}\htext[r]{#1}\end{segment}
  \grrelmove(0,1)}

\grmove(0,-1)
\tick{$-1$}\tick{$0$}\tick{$1$}
% Labels
\move(5,0)\rmove{1}{-90}\htext[t]{$x$}
\grmove(0,0)\rmove{1}{180}\vtext[b]{$\sin(x)$}
% Title
\move(5,5)\rmove{0.5}{90}\htext[b]{\Large Sample Plot}
\end{pspicture}
\end{center}

to get the plot

∗

∗

∗

∗

∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗

∗
∗
∗
∗
∗
∗

∗

∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗

∗

∗

∗

0 \frac{π}{2} π \frac{3π}{2} 2π

−1 0 1

x

sin(x)

Sample Plot

Note how the tick making was aided by the use of the segment environment.

If the file sine.tex were too big to be handled in this way (and this is often the case), you simply replace \input{sine} with \epsmp{sine} and a file sine.eps is created and placed at the appropriate spot.

Please send any comments and errors to: andrew@mast.queensu.ca.