Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot using column header

Tags:

gnuplot

In gnuplot it is possible to use the column name (header) instead of the column numbers.

Let's assume the following datafile 'data.csv':

Time,X1,X2
3600,1,2
3601,3,4
3602,5,6

Now the following two ways are possible:

plot 'data.csv' using 1:2 title 'Param 1', \
     'data.csv' using 1:3 title 'Param 2'

plot 'data.csv' using "Time":"X1" title 'Param 1', \
     'data.csv' using "Time":"X2" title 'Param 2'

But if I want to perform some calculation before plotting - for example to plot the column 'Time' in hours instead of seconds, this is possible with the first way:

plot 'data.csv' using ($1/3600):2 title 'Param 1', \
     'data.csv' using ($1/3600):3 title 'Param 2'

But the following is not possible:

plot 'data.csv' using ("Time"/3600):2 title 'Param 1', \
     'data.csv' using ("Time"/3600):3 title 'Param 2'

How can I perform calculations on columns specified by column header?

like image 369
ped Avatar asked Dec 20 '25 22:12

ped


1 Answers

As suggested by Michael, use column("Time") in your using expression.

plot 'data.csv' using ((column("Time")/3600):2 title 'Param 1', \
      '' using ((column("Time")/3600):3 title 'Param 2'

Documentation for column and using can be found in under the Commands -> Plot -> data section of the gnuplot documentation.

like image 140
kballou Avatar answered Dec 24 '25 12:12

kballou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!