confused
confused

Reputation: 43

Gnuplot: using data from multiple data files for the same plot line

I am trying to generate a gnuplot that uses data from two different data files for the same plot line, something like this:

plot 'datafile1.dat' using 1:($2/('datafile2.dat' using 2)

i.e. x-axis: column 1 from datafile1.dat; y-axis: (column 2 of datafile1.dat) divided by (column 2 of datafile2.dat)

The syntax above is obviously incorrect, but is there a way to achieve this using gnuplot?

An example input data set is as follows: (Both data files have similar set of data)

nSp   Kf  
10    523276.8  
50    6915841.1  
100   24736818.3  
500   622677171.35  
1000  2892599744  
...  

Other solutions I have read online required concatenation of datafile1.dat and datafile2.dat before using plot. The actual data files have many more columns that are used for other plots and hence I wish to avoid this concatenation. If anyone has an alternate solution that keeps the two files separate, I would be very grateful.

Thank you!

Upvotes: 2

Views: 7301

Answers (2)

binzo
binzo

Reputation: 1569

In version 5.4, you can store the second column of 'data2.txt' into a data block and then use it for plotting.

set table $divider
plot "data2.txt" using 2 with table
unset table

plot "data1.txt" using 1:($2/$divider[$0+1]) with linespoints

Upvotes: 3

giordano
giordano

Reputation: 8344

You can merge the two files in a single fictitious file with the paste utility. gnuplot allows to call a command with the "<" syntax:

plot "< paste datafile1.dat datafile2.dat" using 1:($2/$4)

See this example

produced with these two datafiles:

datafile1.dat

1   1
2   2
3   3
4   4
5   5

datafile2.dat

1   3
2   6
3   5
4   4
5   7

Upvotes: 6

Related Questions