jeanc
jeanc

Reputation: 4833

plot function of datasets from different files in gnuplot

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?

Upvotes: 0

Views: 1317

Answers (2)

Dominic Ford
Dominic Ford

Reputation: 234

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.

Upvotes: 1

andyras
andyras

Reputation: 15910

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

Upvotes: 1

Related Questions