Gnuplot exit on window close

北城余情 提交于 2019-12-23 10:09:56

问题


I use the following script to print readings from a .csv file. The plot is refreshed every second to show new data when a simulation is running. This works kinda nice, although is a little ugly since the whole dataset is reread (if you have a better solution please let me know)

However, when I close the gnuplot window the script does not exit, but after 1 second pause a new window spawns, which is kinda annoying. I'd rather have my script closed once i close the window. Is there a way to archieve this?

#!/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

回答1:


There isn't exactly such a functionality in gnuplot, to bind the window's close button to exit the program. However, you can use bind to define a hot-key which exits the loop:

#!/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
}

And no, there is no other way to refresh the plot other than rereading the whole data set every time.




回答2:


To read/reread last 100 lines written to the file which appends whatever new data has arrived

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,\
     ;

I don't have wxt type terminal on my debian system, using an x11 terminal I can bind the key 's' and use it to exit the gnuplot window

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


来源:https://stackoverflow.com/questions/29063622/gnuplot-exit-on-window-close

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!