filedynamicgraphgnuplot

Dynamic Gnuplot graphs


I have a continuously updating data file. I want to use Gnuplot to dynamically plot the updating data file, possibly using a window of the last 100 data points.

Is it possible? If so, some pointers are appreciated.


Solution

  • Here's one way you can accomplish it with Gnuplot and some bash scripting:

    # An updating data file
    while :; do echo $((RANDOM%100)); sleep .1; done > datafile
    

    Initialize Gnuplot with a plot command, and let the other updates come from replot:

    (
      echo "plot [0:100] [0:100] '< tail -n100 datafile' with lines";
      while :; do sleep .4; echo replot; done
    ) | gnuplot -persist
    

    This makes Gnuplot evaluate tail -n100 datafile every .4 seconds and use the result as the data set. The tail command returns the last 100 lines of datafile.