0

I have several files with similar data that I need to plot using gnuplot.

By example, I use something like this to plot the 1st Vs 5th column of 3 files:

plot "file1.csv" using 1:5 title 'test 1' with lp, \
     "file2.csv" using 1:5 title 'test 2' with lp, \
     "file3.csv" using 1:5 title 'test 3' with lp

but, I don't know how to plot a function of the data from the 3 files. By example, I would like to include in the previous plot the media of the 3 columns for each point (that would be the function f(x1,x2,x3)=(x1(i)+x2(i)+x3(i))/3 for the ith data point). Is it possible?

jeanc
  • 4,563
  • 4
  • 22
  • 27

2 Answers2

1

This is a common question, and the answer is: not directly from within gnuplot. You can, however call an external tool to do the math for you. Here are a couple of other answers with examples (you can search this site for 'gnuplot multiple files' for more...):

Example 1

Example 2

Community
  • 1
  • 1
andyras
  • 15,542
  • 6
  • 55
  • 77
1

Another possibility is to use the Pyxplot plotting package http://pyxplot.org.uk, which has similar syntax to gnuplot but cleaned up. Pyxplot has an interpolate command (see http://pyxplot.org.uk/current/doc/html/ex-interpolation.html) for producing functions which interpolate data from files, for example by linear interpolation or a spline fit.

You can then do, for example:

interpolate linear file1() "file1.csv" using 1:5
interpolate linear file2() "file2.csv" using 1:5
interpolate linear file3() "file3.csv" using 1:5
plot file1(x) + file2(x) + file3(x)

which I think is exactly what you're looking for.

Dominic Ford
  • 224
  • 3
  • 2