Gnuplot script error "invalid expression"

Viewed 424

Below is the code meant to output successive images for a gif file:

for i in {1..600}
do
python Phy_asg.py $i
gnuplot <<- EOF
    unset tics;unset key;unset border
    set xrange [-15:15]
    set yrange [-15:15]
    set arrow 1 from 0.012*$i,cos(0.012*$i)-pi to sin(0.024*$i),cos(0.012*$i ) nohead ls 8 lw 2
    set arrow 2 from sin(0.024*$i)+pi,0.012*$i to sin(0.024*$i),cos(0.012*$i ) nohead ls 8 lw 2
    plot "< seq -9 .2 -3.1" u (cos(2*$1)):($1) with lines
    replot "< seq -9 .2 -3.1" u ($1):(cos(2*$1)) with lines
    replot "data_asg.txt" with lines lt 22 lw 2
    set terminal png size 512,512
    set output "Phy_gif_$i.png"
    replot
EOF
done

Here the Phy_asg.py is python script to produce data in form of text file and its name is data_asg.txt. The shell gives me error in the line 10. It says:

gnuplot> plot "< seq -9 .2 -3.1" u (cos(2*)):() with lines
                                      ^
     line 0: invalid expression

I am not able to figure out the problem. Is it with the seq command or formatting error.

1 Answers

The $1 is interpreted as shell parameter instead of data column. Either escape the dollar, \$1 or use column(1), I prefer latter

for i in {1..600}
do
python Phy_asg.py $i
gnuplot <<- EOF
    set terminal png size 512,512
    set output "Phy_gif_$i.png"
    unset tics;unset key;unset border
    set xrange [-15:15]
    set yrange [-15:15]
    set arrow 1 from 0.012*$i,cos(0.012*$i)-pi to  sin(0.024*$i),cos(0.012*$i ) nohead ls 8 lw 2
    set arrow 2 from sin(0.024*$i)+pi,0.012*$i to sin(0.024*$i),cos(0.012*$i ) nohead ls 8 lw 2
    set style data lines
    plot "< seq -9 .2 -3.1" u (cos(2*column(1) )):1, \
         "< seq -9 .2 -3.1" u 1:(cos(2*column(1))), \
         "data_asg.txt" lt 22 lw 2
EOF
done
Related