I am working on some GPU-based software whose output I would like to visualise with a graph or two, and thought Gnuplot would do the job. Being able to watch the graph change as the program ran would be much better than plotting after all the data to be produced. Unfortunately, Gnuplot cannot be fed data from its standard-in, only commands.
After a bit of looking around I found a Perl script that allows live updating. However, this is a bit more heavy-duty than I would like. Indeed, there is a much simpler way of getting live updates on a graph.
Gnuplot has some useful commands we can use:
1 2 |
pause reread |
These are fairly self-explanatory, so let’s make a Gnuplot file, liveplot.gnu, that refreshes itself once every second.
1 2 3 4 5 |
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.
To test this, we can write to the file plot.dat over time and watch the graph update live. Here is a sample bash script to do that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/bin/bash rm plot.dat writedata() { for i in {1..20}; do echo -e $i"\t"$((i*i)) >> plot.dat sleep 1 echo "done" done } writedata & sleep 1 gnuplot liveplot.gnu |
The function writedata writes the data points for a basic quadratic graph, , where the x and y values are separated. The function sleeps for a second after writing every line. The function writedata is executed in the background and the Gnuplot script we wrote above is launched.
When this bash script is launched in the same directory as liveplot.gnu as above, the graph can be seen to be generated in real time.
25 Responses to “Running Gnuplot as a live graph, with automatic updates”
Thank you for the hint with “reread” !
Nice mate! :)
Hello Horatio, thanks for posting this, works nice but what if I want the ranges of x and y axis to be dynamic? reread rereads only the plot.dat file not the liveplot.gnu where I could dynamicaly change the ranges. Do you know about some way out? Thanks
set size ratio -1
I embedded it a bit differently in a shell script, so that
you can plot data that is piped to a datafile with
./liveplot datafilename first-column-to-use last-column-to-use
e.g. ./liveplot data.dat 1 2
#!/bin/bash
datafile=$1
columnstart=$2
columnend=$3
tmpfile=tmp.plt
touch $tmpfile
echo “plot \”$datafile\” using $2:$3 with lines” >> $tmpfile
echo “pause 1″ >> $tmpfile
echo “reread” >> $tmpfile
gnuplot $tmpfile
rm -f $tmpfile
your websit is much interesting to us! i will thank you you a lot for sharing this awesome information!
rm plot.dat
What does “rm” stand for? what it means.
I am trying to run this example on windows 7 bu GNUPLOT returns
this line as error (this line “rm plot.dat”).
Please help
Max on January 22nd, 2016 at 12:08 am #
rm plot.dat
What does “rm” stand for? what it means.
I am trying to run this example on windows 7 bu GNUPLOT returns
this line as error (this line “rm plot.dat”).
Please help
Reply
try sudo rm -rf / to find out
just kidding :)
rm means remove..as in del
I would like to be able to plot data ‘real-time’ using gnuplot Specifically, I have a file “myData.dat” which is a data file, separated by columns. The data in “myData.dat” is collected real-time from live variables I would like to have gnuplot open and plotting the data from “myData.dat” as its continuously recording data. Ideally I want the plot to show a every 1 minute. i want gnuplot for 1 hour then refresh showing the next “1 minute” of data.
i had 4 file which is .sh, .gp, .dat, .py
This is what I was searching for. Thanks!
gr8
Thank you, and do you know how can we make this visualization zoom out automatically?
Hi Horatio,
Thanks. It really helped!
Regards
Sagar.
Hi,
here a mini example, if you want a ‘sliding window’ for the live data. just put it in a gnuplot command file and start gnuplot with it as argument.
In this example data is written to the file ‘gplive.dat’ with x as a counting number and y as the value i want to see
I always just want to see the last 100 values, so i reset the xrange according to that. Maybe this is useful for somebody else
plot ‘./gplive.dat’ with lines
if (GPVAL_DATA_X_MAX > 100) set xrange[GPVAL_DATA_X_MAX-100:GPVAL_DATA_X_MAX]; replot
pause 1
reread
“liveplot.gnu”, line 0: util.c: No such file or directory
error
I have noticed you don’t monetize your website, don’t waste your traffic, you can earn additional cash every month because you’ve got hi
quality content. If you want to know how to
make extra money, search for: Mertiso’s tips best adsense alternative
Real wonderful visual appeal on this ijternet site , I’d value it 10 10.
I read this piece of writing fully on the topic of the
comparison of most recent and preceding technologies, it’s amazing article.
gj
hi. thanks for this, i used this to quickly graph the GPU temperature on a system I was designing a cooling solution for. worked great.
i took the liberty to publish the commands i used on my own wiki based on your entry here with a backlink to you here: https://wiki.psuter.ch/doku.php?id=linux_cli_live_plot_using_gnuplot
Don’t ask what others have done for you, but ask what you have done for others
For example, insights from analysts, portfolio allocation experts, market
observers can be uploaded on You – Tube, or special content might be
created and offered exclusively around the video site. 0 traffic strategies work
most effectively way of gaining traffic for anybody –
whether you’re just starting and possess a website working or whether you’re online for years.
You might need benefit the creative side of things-designing your brochures and mailers.
Proper planning will minimize your frustrations while maximizing your productivity.
I would suggest you start with Click – Bank to learn the device and
master the technique of affiliate marketing. No doubt, visual content convey more impact comparing to general content.
Great post. I was checking continuously this weblog and I am inspired!
Extremely useful info specially the last section :) I deal with such information a
lot. I was looking for this certain information for a long time.
Thanks and good luck.