Gnuplot 在 window 关闭时退出

Gnuplot exit on window close

我使用以下脚本打印 .csv 文件中的读数。 当模拟为 运行 时,该图每秒刷新一次以显示新数据。这很好用,虽然有点难看,因为整个数据集都被重新读取了(如果你有更好的解决方案,请告诉我)

但是,当我关闭 gnuplot window 时,脚本不会退出,但在暂停 1 秒后会生成一个新的 window,这有点烦人。我宁愿在关闭 window 后关闭我的脚本。有办法实现吗?

#!/usr/bin/gnuplot
set t wxt enhanced noraise
set datafile separator ";"
plot "../build/inputLink.csv" using 1:5 title 'Input Gear' with lines ,\
     "../build/inputLink.csv" using 1:7 title 'Input Gear Ratio' with lines,\
     ;
pause 1
reread

gnuplot 中并没有这样的功能,绑定 window 的 close 按钮以退出程序。但是,您可以使用 bind 定义退出循环的热键:

#!/usr/bin/gnuplot
set t wxt enhanced noraise
set datafile separator ";"
set style data lines

done = 0
bind all 'd' 'done = 1'
while(!done) {
  plot "../build/inputLink.csv" using 1:5 title 'Input Gear',\
       "" using 1:7 title 'Input Gear Ratio'
  pause 1
}

不,除了每次都重新读取整个数据集之外,没有其他方法可以刷新绘图。

至 read/reread 写入文件的最后 100 行,该文件追加已到达的任何新数据

plot "< tail -n 100 ../build/inputLink.csv" using 1:5 title \
'Input Gear' with lines , \
, "< tail -n 100"../build/inputLink.csv" using 1:7 title \
'Input Gear Ratio' with lines,\
     ;

我的 debian 系统上没有 wxt 类型的终端,使用 x11 终端我可以绑定密钥 's' 并使用它退出 gnuplot window

pause 1
bind "s" "unset output ; exit gnuplot"
reread