Example 3:

To place more than one curve on a plot, use one plot statement and separate the description of each curve by a comma. In our next example, we will plot both a function and a data file on the same plot. This plot is shown in Figure [*].

    set terminal latex
    set output "eg3.tex"
    set format xy "$%g$"
    set title "This is another plot"
    set xlabel "$x$ axis"
    set ylabel "$y$ axis"
    set key 15,-10
    plot x with lines, "eg3.dat" with linespoints

htbp

\begin{center}\vbox{\input{eg3}
}\end{center}

Here you will see that the x range was not specified. The x range is determined automatically, unless specified by the user. In this case, it is defined by the range of the data file "eg3.dat". The function is plotted over the same range. If no data files or x range are supplied, the default range of [- 10 : 10] is used. We have also moved the key to a different position. The function y = x is plotted ``with lines'', which is the default plot style for functions, and is shown here to illustrate the plot style option. The data file eg3.dat is plotted with style linespoints, a style like lines that also plots a symbol at each data point.

There is a style called points that only plots the symbols at data points, and another called dots that plots a tiny dot for each data point. The points and linespoints styles produce a different point symbol for each curve on the plot (for up to twelve symbols, after which they are re-used). The lines and linespoints styles use a different line style for each curve on the plot (in this example the dots have different spacing). Finally, the style impulses draws a perpendicular from each point to the x-axis.