
The gnuplot program is an extremely useful tool to produce complex graphs for publication and understanding of data. It can take a file containing columns of numbers and display them as a 2D or 3D graph with very little work on your part. This paper is a little lesson in how to go from raw data to graphs.
The following locations have source code or pre-compiled binaries for the current version of gnuplot for various OS's.
On this site you can find all the information including full manuals, reference cards, and links to demos and other tutorials.
There are two ways to use gnuplot, interactively and batch. In the first you start gnuplot and then type into its command line. In the second you hand gnuplot a command file and it plots the data as directed by the file.
We concentrate exclusively on the second, the batch processing where
you produce a file of numbers and then plot them, doing this from a
batch file.
1950 3,632 1,452 104 1,667 385 24.1 9.6 29.2 11.1 2.6The columns correspond to year, births in thousands, deaths in thousands, infant deaths in thousands, marriages in thousands and divorces in thousands. The other columns are same data in rates/1000 which we are not going to use.
1955 4,097 1,529 107 1,531 377 25.0 9.3 26.4 9.3 2.3
1957 4,300 1,633 112 1,518 381 25.3 9.6 26.3 8.9 2.2
1960 4,258 1,712 111 1,523 393 23.7 9.5 26.0 8.5 2.2
1965 3,760 1,828 93 1,800 479 19.4 9.4 24.7 9.3 2.5
1970 3,731 1,921 75 2,159 708 18.4 9.5 20.0 10.6 3.5
1971 3,556 1,928 68 2,190 773 17.2 9.3 19.1 10.6 3.7
:
:
> cat proc.awk
# Extract the first 6 columnsAnd run it via this command line
{
printf("%s\t%s\t%s\t%s\t%s\t%s\n",
$1,$2,$3,$4,$5,$6)
}
And now the data looks like this:
awk -f proc.awk dataraw.txt > data.txt
1950 3,632 1,452 104 1,667 385One more item, we then edit the file with a text editor to remove the ',''s in the numbers (gnuplot doesn't like them....)
1955 4,097 1,529 107 1,531 377
1957 4,300 1,633 112 1,518 381
1960 4,258 1,712 111 1,523 393
1965 3,760 1,828 93 1,800 479
1970 3,731 1,921 75 2,159 708
1971 3,556 1,928 68 2,190 773
1950 3632 1452 104 1667 385
1955 4097 1529 107 1531 377
1957 4300 1633 112 1518 381
1960 4258 1712 111 1523 393
1965 3760 1828 93 1800 479
1970 3731 1921 75 2159 708
1971 3556 1928 68 2190 773
#Saving this to plot.txt
# Plot the census data
# Plot YEAR vs various fields]
# Data is: YEAR BIRTHS DEATHS INFANT Marriages Divorces
# Total Deaths
#
set title 'Vital Statistics' # This is the label for the entire graph
set xlabel 'Year' # This is the X Axis label
set ylabel 'Number (1000)' # This is the Y Axis lable
set grid # This puts a grid on the graph
#
# These next lines do the heavy lifting and plot the data
# Note: The \' at the end of the lines, this is actually 1 very long
# line the \' escape the end of line characters. Don't type
# anything after them but your RETURN
# plot - Says plot the data from "data.txt" the file we created
# using says use these columns of data for this line 1:2 says
# use column 1 as X and column 2 as Y
# with line says connect the points with a line
# You can also say with point or with dot for different styles
# title '<name>' gives a title to this line and puts that
# name and color into a legend on the graph
plot "data.txt" using 1:2 title 'Births' with line,\
"data.txt" using 1:3 title 'Deaths' with line,\
"data.txt" using 1:4 title 'Infant Deaths' with line,\
"data.txt" using 1:5 title 'Marriages' with line,\
"data.txt" using 1:6 title 'Divorces' with line
gnuplot plot.txt