Get ratio from 2 files in gnuplot

You cannot combine the data from two different files in a single using statement. You must combine the two files with an external tool.

The easiest way is to use paste:

plot '< paste a.dat b.dat' using 1:($2/$4) with linespoints

For a platform-independent solution you could use e.g. the following python script, which in this case does the same:

"""paste.py: merge lines of two files."""
import sys

if (len(sys.argv) < 3):
    raise RuntimeError('Need two files')

with open(sys.argv[1]) as f1:
    with open(sys.argv[2]) as f2:
        for line in zip(f1, f2):
            print line[0].strip()+' '+line[1],

And then call

plot '< python paste.py a.dat b.dat' using 1:($2/$4) w lp

(see also Gnuplot: plotting the maximum of two files)

Leave a Comment