Is it possible to define functions that work with input data

I wonder if there is some workaround in Gnuplot for sharing 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 my raw data (string) before plotting.

+5
source share
2 answers

You can, using the syntax very close to what you suggested. Define the following functions:

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

And use them as follows:

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

This parenthesis node in the plot statement is necessary.

You can define functions of more than one variable:

func3(x, y) = x * y

They are used similarly:

plot "input.dat" using (func1($1)):(func3($1, $2))
+9
source

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

:
Data.csv:

0.65734 0.59331
0.60033 0.76434
0.66493 0.43881
0.42811 0.42567
0.01783 0.57760

, :

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

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

"" func1($1) func2($1, $2). gnuplot, .

+3

All Articles