Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one define functions which operate on input data

I wonder if there is some workaround in Gnuplot to exchange something like

plot  input.dat using ($1/2):($2*2) axis x1y1 w lp

with

plot  input.dat using func1($1,$2):func2($1,$2) axis x1y1 w lp

with

func1(x,y) = x/2; func2(x,y) = y*2;

?

I would like to post-process my input data (line) before plotting.

like image 854
Denis Avatar asked Nov 28 '11 13:11

Denis


2 Answers

You can, using syntax very close to what you've suggested. Define the functions like this:

func1(x) = x / 2
func2(x) = x * 2

And use them like this:

 plot "input.dat" using (func1($1)):(func2($2))

That knot of parentheses in the plot statement is necessary.

You can define functions of more than one variable:

func3(x, y) = x * y

These are used similarly:

plot "input.dat" using (func1($1)):(func3($1, $2))
like image 111
Michael J. Barber Avatar answered Sep 30 '22 20:09

Michael J. Barber


You can use functions in gnuplot. It is documented here.

As an example:
With the data file Data.csv:

0.65734 0.59331
0.60033 0.76434
0.66493 0.43881
0.42811 0.42567
0.01783 0.57760

you can plot the data using functions like this:

func1(x) = x/2
func2(x,y) = y*2

plot "Data.csv" u (func1($1)):(func2($1, $2)) w l

Note the "extra" parentheses around func1($1) and func2($1, $2). These tell gnuplot to evaluate the expression within them.

like image 33
Woltan Avatar answered Sep 30 '22 21:09

Woltan