set terminal latex set output "eg2.tex" set size 5/5., 4/3. set format xy "$%g$" set title "This is a plot of $y=sin(x)$" set xlabel "This is the $x$ axis" set ylabel "This is\\the\\$y$ axis" plot [0:6.28] [0:1] sin(x)
htbp
We have specified the plot to be 5 inches wide and 4 inches tall with the set size command. This is the size of the area used by the plot, including space for the labels. In the first example, this size was the default 5 inches by 3 inches. By specifying the scaling factors of 1 (or 5/5) and 1.3333 (or 4/3), we obtain the desired plot size.
We have requested that the format used by the x- and y-axis tic
mark labels be in LATEX math mode. This makes the labels look a
little better. The default is set format xy "%g"
. The %g
represents the general-purpose floating point formatting specification
for the printf function in C. Any valid floating-point
formatting specification, or LATEX command, is allowed in the
format.
A title for the plot and labels for the axes were set up in the next
three commands. Note that they are processed by LATEX and so may
have math mode and other symbols in them. The ylabel may have multiple
lines, delineated with \\
. Once these are set up, they will be
used for all subsequent plot commands until they are changed. These
labels are also supported by the other terminal types, but (of course)
any LATEX code in the string will not be interpreted. We have also
defined the range of both x (now [0, 2π]) and y (here [0, 1]).
So far we have plotted one curve, y = sin(x), on one plot. In GNUPLOT, each plot command generates a new plot. If the output is to a screen, the screen is cleared. If to a printer, a new page is produced. In the latex case, a new picture is started. It is not likely that LATEX users will want this to happen, so generally each plot has its own input file and is kept in a separate output ( .tex) file for inclusion at different places in the document.