I'm making a script to plot desired pairs of columns of a datafile in a window. But i cant figure out how to make gnuplot accept arguments to the using command.
my code looks like this
#!/bin/bash
filee=$1
shift 1
cols=$@
gnuplot -p << eof
#TESTS--------------------------------
print "gnuplot--starts----------------"
print "cols-var is: $cols"
print "filee-name is: $filee"
print "pair-vars are:"
do for [pair in "$cols"] {print pair}
print "-------------------------------"
#END TESTS----------------------------"
set term wxt 1 size 1500,900 title 'columns of $filee'
set key top left
set grid
set xrange [2:8]
set yrange [-0.02:0.02]
set format y "%g"
plot for [pair in "$cols"] '$filee' u pair
eof
If instead of pair as the argument to u i use 1:3 or 1:2 or whatever i get the correct number of plots, but of course they are all identical. I tried a lot of things and everything seem to be working besides that u doesn't accept a variable. The output wher running this is:
$ ./cploter written.dat 1:2 1:3 1:4
gnuplot--starts----------------
cols-var is: 1:2 1:3 1:4
filee-name is: written.dat
pair-vars are:
1:2
1:3
1:4
-------------------------------
line 0: warning: Skipping data file with no valid points
line 0: warning: Skipping data file with no valid points
line 0: warning: Skipping data file with no valid points
Some help with this issue would be appreciated:)
EDIT: as u doesn't seem to be accepting the loop through its arguments I settled for the code below. If You know a different approach to plot desired column pairs into one plot, please leave a comment or answer:)
#!/bin/bash
fil=$1; xx=$2; y1=$3; y2=$4
gnuplot -p <<- eof
set term wxt 1 size 1500,900 title 'columns of $filee'
set key top left
set format y "%g"
plot for [i=${y1}:${y2}] '$fil' u ${xx}:i w l t 'Column ${xx}:'.i
eof
I'm on gnuplot 4.6. using for [i in $range] does not work in this case for some reason. Using variables ys(i)=word("$yes",i), xs=word("$xes",i) and plot for [i=1:3] '$fil' u xs(i):ys(i) w l doesn't work either.