next up previous
Next: GnuPLOT Example Problems Up: GnuPLOT Previous: Installation and Usage

Basic Graphing

Once the GnuPLOT package is installed we can begin graphing some simple equations. For the remainder of the document we will assume a Linux/X11 configuration.

Begin by starting the GnuPLOT executable:

Our first plot is the simplest case of a horizontal line:

$\displaystyle f(x)=C $

This is, of course, a horizontal line passing through the point (x, C). If we assign a value to C we can plot by doing:

  gnuplot> plot 5

To make this a more interesting plot (as these things go), we can plug in different values into the equation of a line:

$\displaystyle f(x)=mx + b $

Linear equations form the basis for later analysis. Though the equation of a line is straightforward, 1 a thorough understanding of its twists and turns is necessary to grasp the calculus and complex analysis. In this next example we will use GnuPLOT to graph variations on the line. The power of the graphing tool becomes apparent when one aspect of a function is changed and the resultant graph is updated.

For the next example we will adjust how the graph is displayed by turning on the background grid. We'll graph the function $ f(x)=2x + 1$ by typing the following commands:

  gnuplot> set grid 
  gnuplot> plot 2*x + 1

Figure 1 shows the resulting plot. You may notice that the graph covers a large range and domain. There are many instances when it would be more enlightening to concentrate on a particular section of the graph. For example, in the graph of a quadratic equation we would generally be concerned about the zeroes or vertex rather than the overall plot. To limit GnuPLOT to a range or domain use the following:

  gnuplot> plot [-5:5] [-6:6] 2*x + 1

In this case we have limited the section of plot to 5 units above and below the X axis and 6 units to the left and right of the Y axis. Of course, were we to zoom in to very small sections of the line or to zoom out to very large sections, the line would still look very much the same.

Thus, our next example is a standard quadratic of the form:

$\displaystyle f(x)=ax^2 + bx + C $

We'll arbitrarily assign values and plot the equation $ f(x)=2x^2 + 3x + 4$ by typing:

  gnuplot> plot [-3:2] [1:5] 2*x**2 + 3*x + 4

Figure 2: A Quadratic Equation
\includegraphics[height=112pt,width=160pt]{images/plot_0001.eps}

Note that we explicitly show multiplication by using the asterisk. We use the double-asterisk to specify exponentation. Finally, GnuPLOT takes care of the order of operations, as it should, and explicit parentheses are not needed around the $ x^2$ term.

We are not limited to graphs within the XY plane as GnuPLOT can easily graph in three dimensions using the splot command. For example, to plot the somewhat visually interesting graph of $ f(x,y)=sin(x)cos(y)$ we enter the following:

  gnuplot> set grid
  gnuplot> set isosamples 40
  gnuplot> set hidden
  gnuplot> splot [-5:5] [-5:5] sin(x) * cos(y)

Figure 3: Plot of 3-Dimensional function
\includegraphics[height=225pt,width=320pt]{images/plot0002.eps}

Figure 3 shows the graph of this function. The lines of interest are the set isosamples and set hidden commands. The higher isosamples will increase the apparent smoothness of the plot. The hidden command removes hidden lines from the plot. Hidden lines are portions of the graph that are occluded behind the graph in the foreground.


next up previous
Next: GnuPLOT Example Problems Up: GnuPLOT Previous: Installation and Usage
Kwan Lowe 2003-01-31