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.
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))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With