Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically replot a graph every few seconds in gnuplot?

I have a data file a.dat that is updated every few seconds. I wish to plot it in gnuplot every few seconds to see the changes

plot "a.dat"

What is the easiest way to do it? Thanks.

like image 509
hbp Avatar asked Feb 10 '15 23:02

hbp


2 Answers

Make a script with a loop:

while (1) {
    plot "a.dat"
    pause 1      # waiting time in seconds
}

Execute it with gnuplot script.gp.


For purposes of code structure and debugging, you might prefer the following alternative:

plot "a.dat"

while (1) {
    replot
    pause 1
}

This has the advantage that you do not have to put a complicated plot command inside the loop and do not suffer from incorrect line numbers for the plot command in error messages (that happen in at least some version of Gnuplot).


Finally, if your Gnuplot is so old that it does not yet support loops, there is the alternative:

plot "a.dat"

pause 1
reread

With reread making the script interpreter jump to the beginning of the file again.

like image 125
Wrzlprmft Avatar answered Sep 22 '22 00:09

Wrzlprmft


If gnuplot is called with plot commands in the command line (option -e) instead of a command script file, only the version

gnuplot -e "...plot command(s)...; while (1) { pause 1; replot; }"

worked in my case, the other version

gnuplot -e "...plot command(s)...; pause 1; reread;" 

did not.

On windows 10, I have to kill the gnuplot task in the task manager, because if I close the gnuplot window with the close-window-button, the window opens again after one second latest. Does anybody have an idea of how to handle this in a more comfortable way?

like image 24
mjavu Avatar answered Sep 18 '22 00:09

mjavu