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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With