【问题标题】:Gnuplot script error "invalid expression"Gnuplot 脚本错误“无效的表达式”
【发布时间】:2020-10-08 17:56:05
【问题描述】:

以下是用于为 gif 文件输出连续图像的代码:

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

这里的Phy_asg.py是python脚本,以文本文件的形式生成数据,它的名字是data_asg.txt。 shell 在第 10 行给了我错误。它说:

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

我无法找出问题所在。是seq命令还是格式错误。

【问题讨论】:

    标签: bash gnuplot seq


    【解决方案1】:

    $1 被解释为 shell 参数而不是数据列。要么逃避美元,\$1,要么使用column(1),我更喜欢后者

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      相关资源
      最近更新 更多