Plotting with gnuplot
Visualising data quickly and effectively in diagram form is a common and frequent requirement. Gnuplot, the program we will be looking at in this article, has provided this functionality for years. Gnuplot is a plotting tool that can be ported to nearly every major platform. Gnuplot 4.0 is the latest version of this tool.
How to plot graph
'plot' is the primary command, which is used to draw a graph with Gnuplot 4.0. Syntax is
plot {<range>} {<function> | {"<filename>" using {datafile-modifiers}}} {with <style>}
In this syntax we have to supply the function or datafile name. Data file is simple text file and may be generated by a program. Function is a mathematical expression. The expression can be defined completely. Ranges can be the X-range and Y-range of the graph. In datafile-modifiers we can select columns to plot data. Style can be points, linespoints, boxerrorbars, boxes, dots, steps, vectors etc. The shape and color of lines or points can be changed by changing style parameters.
For example:
plot <filename> will plot data from file 'filename'
plot <filename> using 3:5 will plot data available from third and fifth column of file 'filename'. Instead of 'plot' and 'using' commands we can use their short forms like 'pl' for 'plot' and 'u' for 'using'.
Here is simple plot example This 'sample.txt' file contains description about graph.
--"sample.txt"--
set title "Graph for road plot readings"
set xlabel "chainage"
set ylabel "height"
set grid
set label "20,8" at 20.2,8.2
set term png small
set out "graph_l_sect.png"
plot "l_section" using 1:2 with linespoints.
'l_section' is the name of the data file.
- 0 10
- 10 9
- 20 8
- 30 7
- 40 6
gnuplot sample.txt will plot data from file sample.txt and give title, labels to graph.
Here is graph of this datafile.

Here is second example.
