Fitting the grid to the data
gnuplot, by default, arranges our graph with a set of ticmarks at equally spaced intervals, with gridlines to match (if we turn the grid on). If we want to make it easy to read off the values of a particular set of points, we can do better:
How to do it…
The following script will create the previous figure:
set term pngcairo dashed set out 'xsquared.png' set samples 6 set key top left set for [n = 1 : 4] arrow from first n, 0 to first n, n**2 back \ nohead lt 7 set for [n = 1 : 4] arrow from first 0, n**2 to first n, n**2 back \ nohead lt 7 set for [n = 0 : 5] ytics (n**2) plot [0:5] x**2 with linespoints pt 7 ps 3
How it works…
We have included explicit set terminal
and set out
commands because we want our linetype specifications to select a dashed line; if you prefer to use colored lines where the figure has a dashed line, you can omit the dashed
keyword.
We set a small number of samples because we want to illustrate the technique with a handful of points, that typically...