next up previous
Next: Running ePiX Up: A Simple Figure and Previous: A Simple Figure and

Plotting Functions

ePiX has several commands for creating plots of user-specified functions. Suppose we wish to graph the sin function on the interval $ [-3,3]$, emphasizing that while not invertible, it is invertible on the interval $ [-\pi/2,\pi/2]$. Because the sin function is provided in  C, we need not define it. Our input file might look like Figure 3. The resulting LATEX output is Figure 4.

Figure 3: The source file for Figure 4.
\begin{figure}
\begin{verbatim}/* sine.c -- The graph y = sin x on [-3,3] */
...

The figure is 300pt wide and 100pt high, and uses the constant M_PI_2. The axis-generating commands are new, but the syntax is easily divined; note that their positions (and the number of tick marks) are specified completely in terms of the bounding box. This works well as long as the bounding box has integer coordinates. The plot commands are of primary interest:


  plot(sin, x_min, -x0, 30);
draws a plot of the sin function between x_min and $ -\pi/2$, using 31 data points. The other plot lines are similar.

Figure 4: Plotting the sin function with ePiX.
\begin{figure}
\begin{center}
\input{sine.eepic}
\end{center}\end{figure}

An ePiX figure is built in layers, with later parts of the file set atop earlier parts. Generally you needn't pay much attention to the order in which objects appear in a source file, but in the sin graph example there are two opaque layers whose occlusion of lower layers is deliberate. First, the axis labels are ``masked'', meaning they are set atop opaque white rectangles; this is done to prevent the graph from colliding with the label at $ -3$. Second, the bold portion of the graph passes over the mask at the origin. Consequently, the plain sin graph, then the axis labels, then the bold sin graph must appear in order in the source file. Layering tends to be more of an issue with color figures, since it is more apparent which of two curves passes over the other when their colors are different. Generally, masked axis labels should come last in a file, since the purpose of masking is to make the labels legible.

The number of points in a function plot should be as small as possible without compromising quality, an aesthetic decision. LATEX reads in all the points in a path before typesetting anything, and is likely to run out of memory if the path contains more than about 700 points. There may be other limits on the total number of points a previewer is able to display.

ePiX provides plotting commands that do clipped, polar, or parametric plotting, draw slope or vector fields, or plot solutions to systems of ODEs, but they all operate similarly to plot: You provide the function(s) to be plotted, a range of values over which to plot, and the number of sample points.

Eventually, you will want to define your own functions for plotting. This is described in Section 3. Function (and variable) names may consist of letters, numerals, and underscores, and may not begin with a numeral. Names are case sensitive; the convention is to use lower-case names, but you need not do so. It's a good idea to use descriptive, relatively short names that are logically related to what they stand for. If the compiler complains that a function (or variable) is ``multiply defined'', it means the name has been previously declared.


next up previous
Next: Running ePiX Up: A Simple Figure and Previous: A Simple Figure and
hwang
2002-06-06