Qplot for Gnuplot
[gnuplot]
[qplot]
[operation]
[requirements]
[download]
[samples]
[utility]
Gnuplot is a very full-featured graphing/plotting program, with the added
attractions of being free and open-source.
- Find out about gnuplot here.
- Download it from here.
- Find current gnuplot "betas" here.
- Obtain a full manual in pdf format
here.
One limitation of gnuplot from an economist's point of view is that it is not
set up to handle quarterly time-series data with ease. You can plot such data
OK, but it's difficult to get the time-axis tic labels to come out right (e.g.
"1960.1", "1995.4"). Gnuplot actually has a sophisticated and flexible
mechanism for handling time on the x-axis, but it is based on the unix time
"struct", which does not recognize the quarter-year as a primitive unit of
time, so you have to go through some contortions to get the labels right.
The little package here is designed to make the plotting of quarterly data
easy. It takes the form of two files:
- a perl script, gp_quarters.pl that acts as
a "pre-processor" for a quarterly time-series data file, putting it into a
form suitable for use with gnuplot, and also writes out a set of gnuplot
commands for creating the time-axis tics and labels. The modified dataset is
written to a temporary file.
- a gnuplot command file qplot.gp that interfaces
with the perl script. This file can be called from the gnuplot command line,
or from within an existing gnuplot command (batch) file.
Here is the modus operandi:
- First ensure that your data file meets the required specification: the
first column should contain quarterly dates in the standard economist's
format, e.g.
1960.1
, 1995.3
, 47.1
(years can be given in 4 or 2 digits; quarters are given as 1 digit following
a "decimal" point). The remaining columns can contain any number of data
series. Any "comment" (non-data) lines should have a "#" in the first
column. A little example is given in the file q2.dat.
- Ensure that gp_quarters.pl is in your path, and that
qplot.gp is in the current working directory.
- In gnuplot, issue a command of the form:
call "qplot.gp" "<datafile>" "<plot parameters>" {<maxtics>}
For example
call "qplot.gp" "econ.dat" "using 1:2 with lines" 12
Note that the first 3 fields after call
must be quoted. Supply
the name of your original datafile: the perl script will write out a temporary
modified version (qdata.tmp
) and use this for the plot. Then
supply the parameters to the plot
command that you wish to
use, as usual but quoted (see the gnuplot manual for details). Finally
(and optionally) supply an integer representing the maximum number of
date-labeled tic marks to place on the x-axis. This defaults to 12.
- The qplot script uses the "call" command in gnuplot. This requires
gnuplot version 3.7 or higher.
- The main work is done by perl, so you need to have perl installed.
- If you're using a non-un*x operating system, you'll probably have
to edit qplot.gp, changing the "rm" to "del" to get rid of
the temporary files that qplot generates.
You can simply grab the files mentioned (and linked) above. Or you
can grab a zipfile containing everything, including a copy of this
page and some sample datafiles: qplot.zip.
Qplot is governed by the GNU Public License.
These simple plots are designed to illustrate the date handling
capacity of qplot.
Sample 1:
set size .8,.8
set term gif
set output "sample1.gif"
set title "Gross domestic product (AR, bil. 1987 $) 1948.1 - 1993.3"
set nokey
call "qplot.gp" "q3.dat" "using 1:2 w l"

Sample 2:
set size .8,.8
set term gif
set rmargin 4
set output "sample2.gif"
set title "Gross domestic product (AR, bil. 1987 $) 1948.1 - 1950.4"
set nokey
call "qplot.gp" "q2.dat" "using 1:2 w l"

Sample 3:
set size .8,.8
set term gif
set rmargin 4
set output "sample3.gif"
set title "Gross domestic product (AR, bil. 1987 $) 1948.1 - 1950.4"
set nokey
call "qplot.gp" "q2.dat" "using 1:2 w l" 6

Do you have a datafile containing quarterly time series data, but without the
required date markers in the first column? Here is a little perl filter that
adds dates: add_quarters.pl. The
useage is, for example:
add_quarters.pl 1956.1 < econ.dat
That is, supply a starting date in the form YYYY.Q (or YY.Q) and
supply the name of an existing datafile on standard input: the
datafile with dates added will appear on standard output.
Allin Cottrell
(cottrell@ricardo.ecn.wfu.edu)
May, 1999