set terminal latex
set output "eg4.tex"
set format y "$%g$"
set format x "$%.2f$"
set title "This is $\sin(x)$"
set xlabel "This is the $x$ axis"
set ylabel "$\sin(x)$"
set nokey
set xtics -pi, pi/4
plot [-pi:pi] [-1:1] sin(x)
Since pi is a predefined variable in GNUPLOT, we can use it
anywhere we may use an expression. The set xtics command here
specifies that the tics on the axis start at
and increment
by
. Since no end point is given, the tics continue to the
right edge. We have also turned off the key, and changed the format to
restrict the
-axis tic labels to 2 decimal places.
With a little more work, the plot can look even better. Another form of this command allows us to specify the label and position of each tic individually. Replacing the above set xtics command with the following gives us Figure 5. We also make use of the line continuation character, the backslash (\), to spread out this command for readability.
set xtics ("$-\pi$" -pi,\
"$-\frac{\pi}{2}$" -pi/2,\
"0" 0,\
"$\frac{\pi}{2}$" pi/2,\
"$\pi$" pi)