8

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.

3 Answers 3

15

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This solution has the disadvantage that gnuplot may sometimes read incomplete input from a.dat when it happens to read the file exactly while it is written by the other application.
Marcel: you must swap the file atomically. Most OS'es can do this. Here's how I do this from Clojure: gist.github.com/lnostdal/cc956e2a80dc49d8097b7c950f7213bd
4

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?

Comments

0

The accepted solution, of a script with a loop, works for me on a Ubuntu computer. To resolve the problem mjavu raised, which was needing a clean method to stop the script and associated task running, Ctrl-C in the terminal window works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.