mwarning
mwarning

Reputation: 791

How to put a gnuplot formula into a variable

I have a gnuplot graph that has some big formula and repeated formular to calculate some y value. A bit like this one:

plot 'data1.csv' using 1:(column('a') / column('b') / 1000) with linespoints title 'data 1',
'data2.csv' using 1:(column('a') / column('b') / 1000) with linespoints title 'data 2';

Is it possible to move out the formula into a variable? Maybe something like (but not working):

y = (column('a') / column('b') / 1000)
plot 'data1.csv' using 1:y with linespoints title 'data 1',
'data2.csv' using 1:y with linespoints title 'data 2';

Upvotes: 0

Views: 341

Answers (1)

Ethan
Ethan

Reputation: 15118

Not into a variable (scalar), but you can define a function:

  y(v1,v2) = column(v1) / column(v2) / 1000
  plot 'data1.csv' using 1:(y('a','b')) with linespoints title 'data 1'

In your particular case the function need not take the actual column identifiers as parameters because they are constant. So a simpler function with one dummy parameter is possible

  y(dummy) = column('a') / column('b') / 1000
  plot 'data1.csv' using 1:(y(0)) with linespoints title 'data 1'

Upvotes: 2

Related Questions