Saturday, May 29, 2004

Graphing with gnuplot

When I first started writing papers, drawing a graph was not too hard. First you sketched out your picture on a sheet of paper. If you were plotting data, you'd used graph paper. For really accurate plots you'd use graph paper with ten lines per millimeter. A photocopy of that would be sent to the journal along with your (typed) manuscript. After the article was accepted, you'd take the figures to the draftsman, who would draw it up with pen and ink, who would send this work of art (and it was) to the camera shop, where they'd take a picture of it and give you a few 8x10" glossies, one of which was mailed to the journal. At the journal they would take pictures of this glossy and send it to their production people, who would get it into the journal somehow.

Eventually computer graphing programs came along. They'd even produce PostScript (TM) files, which could be emailed directly to the publisher. The question was, which program should I use?

I tried a few. We even bought some. But sometime in the early 1990's I found references on Usenet and Gopher to a program called gnuplot. Logically, you'd think this was related to the Free Software Foundation's GNU project, but it's not, the name is a coincidence. In any case, gnuplot was easy to use, had a command line interface that enabled you to use it in script files, and, eventually, came up with an enhanced PostScript interface which let you do a reasonably good job of drawing subscripts, superscripts, and Greek characters.

Oh yeah, sometime after 1995 it also came with a curve fitting routine. Give gnuplot your data an a parameterized function, and it would do its best to find the proper parameters to fit the curve.

I still use gnuplot, but the current version included with Fedora Core 1 is 3.7, released many years ago. Many people have moved to other software programs that I don't understand so well. A popular one where I work is Grace.

So now there's a new gnuplot, version 4.0, released in April. It looks to have more colors, better contour support, etc., yada... I wouldn't know, I just got it installed. I didn't find and RPMs for it I trusted, so I downloaded the source code, and ran my usual
$ ./configure --prefix=/home/local
$ make install

which installed the program in /home/local/bin, where I like to keep programs that don't need to be run as root. And the program worked. Except if I have a selection of gnuplot scripts called, say,
plot1.gnu plot2.gnu plot3.gnu ...
and try to load them using
gnuplot> "plo[TAB]
nothing happened. In other words, filename completion was dead. This works with most older versions of gnuplot.

Turns out that to do this you need the GNU (which is not gnuplot) version of the readline libraries. OK, I have that on this machine, so we try
$ ./configure --prefix=/home/local --with-readline==gnu
$ make install

And this works. Except that there is a bug in GNU readline. If you understand what that message said, don't tell me. Just note that the effect of the bug is that, if you call gnuplot from the command-line prompt from an xterm, have it put up a plot (say
gnuplot> plot x
and then resize the xterm, the gnuplot figure vanishes. Why? I have no clue. Anyway, you can get it back by using the
gnuplot> replot
option.

Is gnuplot 4.0 better than 3.7? I don't know yet. But at least I've got it working.

0 comments: