GNUplot hacks

I love GNUplot, especially the latest (4.2) version. Between GNUplot and Perl, I can do any data manipulation I want and produce any plot I like. However, there are a few annoying things that need taking care of by hand or need to be configured manually.

Using readline with GNUplot

Sometimes, an installed version of GNUplot is not linked against readline. This is a royal pain in the rear, but easily fixed by compiling your own version of gnuplot. Ok, so that's not really a hack.

Grab a source tarball or, better yet, grab the current CVS version of GNUplot. Read the documentation that comes with it for good measure, then run

autoconf
./configure --prefix=$HOME --with-readline=gnu --enable-history-file
make -j
make install

Leave out the --prefix option if you want to install in the default location. You probably need to be root for the final step.

Getting it to work on OS X

For some reason, OS X seems to be broken in some way, or at the very least readline is not detected on my Mac, despite being installed and working fine.

There is a readline check specifically for OS X in configure.in. I hacked that so that it always succeeds, but then I still had to edit config.h to enable both readline and history there. After recompiling, everything worked fine.

GNUplot can't read FORTRAN output files!

Yes, it can. Some FORTRAN code still insists on using "D" to denote an exponent, rather than "E" like everyone else. GNUplot can read these just fine, but it needs to know that the file you're trying to read is in this broken format. Just give

set datafile fortran

and things will work. You may want to add that option to your ~/.gnuplot file.

I'd like to do subscripts and Greek symbols in my X11 windows...

set terminal x11 enhanced

I need different linestyles with the same colour/different colours with the same linestyle.

This used to be really annoying with older versions of GNUplot. You could do it for the PostScript output (which is what I normally use myself) by hand-editing of the PostScript file. There are several guides on the Internet that explain how if you're not familiar with editing PostScript files (it's not hard).

New versions of GNUplot, however, have a linecolor option that allows you to set the line colour without resorting to ugly hacks.

I want to specify a background colour for the box around my key

Imagine lots of lines or shaded regions overlapping with your key and making it unreadable. That's annoying. A workaround can be to place the key below the graph, but sometimes that's not a good solution (multiplot environments come to mind). There doesn't seem to be a way to fix this within GNUplot at the moment, but here's how to hack it into the PostScript output:

  1. Open the offending PostScript file
  2. Find the location where the key is defined (search for one of the strings in the key). An example of what you might see:
    LTb
    4379 4249 N
    0 560 V
    2583 0 V
    0 -560 V
    -2583 0 V
    Z stroke
    4379 4809 M
    2583 0 V
    1.000 UP
    stroke
    LT0
    LCb setrgbcolor
    6395 4739 M
    [ [(Helvetica) 140.0 0.0 true true 0 (Adiabat t = 1000 Myr)]
    ] -46.7 MRshow
          
    The five lines immediately below the 4379 4249 N line are the drawing commands for the box around the key. What we need to do is tell GNUplot to fill this contour with a colour of our choice and then draw the line. Easy:
    LTb
    4379 4249 N
    0 560 V
    2583 0 V
    0 -560 V
    -2583 0 V
    gsave
       1 setgray
       fill
    grestore
    Z stroke
    4379 4809 M
    2583 0 V
    1.000 UP
    stroke
    LT0
    LCb setrgbcolor
    6395 4739 M
    [ [(Helvetica) 140.0 0.0 true true 0 (Adiabat t = 1000 Myr)]
    ] -46.7 MRshow
          
    The box now has a white background colour.
Valid HTML 4.01! Valid CSS!