plotgnuplot

How can you watch gnuplot realtime data plots as a live graph, with automatic updates?


I plot a lot of graphs in gnuplot. These graphs are based onn sensor readings from around the solar power system.

Each graph has needed to be updated by typing something like

load "solar

where solar is a gnuplot program that performs the plot showing the condition of the 24 V (500Ah) battery bank and leaves it on the screen so I can do a regional screen capture for storage.

In this particular case, the numbers come in at 2-minute intervals. Unless the inverter is turned on, in which case they come in at 20 second intervals. So I end up typing that command a lot just to see how clean the signal is.

So the question came up as to whether I need to continue to tell it to load the program every time I want to see updates.

How can I actually make it automatically live?


Solution

  • Turns out it is as simple as can be to have it run live.

    This article: Running Gnuplot as a live graph, with automatic updates

    explains the process nicely.

    Turns out that all you need to do is add two lines of code after the plot command. In my case, I want it to update the graph every 15 seconds, so the last two lines of the program are simply

    pause 15
    reread
    

    Here is an excerpt from the article:

    Gnuplot has some useful commands we can use:

    pause
    reread
    

    These are fairly self-explanatory, so let’s make a Gnuplot file, liveplot.gnu, that refreshes itself once every second.

    set xrange [0:20]
    set yrange [0:400]
    plot "plot.dat" using 1:2 with lines
    pause 1
    reread
    

    We set the bounds of our graph, then plot the data from the file. using 1:2 means plot columns 1 and 2 as x and y, respectively. with lines means that the points are joined together rather than plotted separately. We pause for 1 second and then reread, meaning that the command file is re-executed.

    It turned out to be so simple that I am going to add those two lines to all my graphs that I monitor on the xterminals of the individual Rpi3s that monitor the sensors.

    Collected together on the big screen it gives me a great overview of the entire system, including temperatures and voltages and such.

    The best part is that there is no need to specify the X range to be fixed. It is much better to let it recalculate every time it rereads.

    Results: A true live graph, monitoring conditions of the sensors from which it is receiving near-real-time data.

    enter image description here

    (You can see how hot the panels get even on a relatively cool day, and how the MPPT charge controller works to maintain the voltage)

    https://www.SDsolarBlog.com/montage