Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot graphs in Gnuplot in Real time in C++? [closed]

I'm trying to plot a graph in real time using GNUplot and C++. Does anyone know of any good libraries that does this? Thanks

like image 630
chutsu Avatar asked Dec 15 '10 00:12

chutsu


3 Answers

gnuplot supports input via pipes (on windows, there's a separate executable for this, pgnuplot). Then your program can send new commands to gnuplot, such as replot, just as if you were typing them into the gnuplot interface directly.

How you set up the pipe connection and write to the sending end of the pipe from your C++ program varies by operating system, so you'll have to tell us what you're using if you want more help.

On Windows, there's CreatePipe and then you set the hStdInput element of the STARTUPINFO struct you pass to CreateProcess. Ditto with hStdOutput if you need the status messages from pgnuplot.

On POSIX (Unix, Linux, Mac OSX, etc), you can just use popen as the quick way to get a unidirectional connection. For bidirectional, it works more like on Windows: pipe to get handles to the ends, then fork and in the child process call dup2 to associate stdin and stdout with the pipe, then exec to have gnuplot replace the child process, keeping the pipes you set up.

EDIT: From the gnuplot documentation:

The special filename ’-’ specifies that the data are inline; i.e., they follow the command. Only the data follow the command; plot options like filters, titles, and line styles remain on the plot command line. This is similar to << in unix shell script, and $DECK in VMS DCL. The data are entered as though they are being read from a file, one data point per record. The letter "e" at the start of the first column terminates data entry. The using option can be applied to these data — using it to filter them through a function might make sense, but selecting columns probably doesn’t!

like image 152
Ben Voigt Avatar answered Nov 16 '22 21:11

Ben Voigt


Have you tried gnuplot interfaces in ANSI C?, this is an interface for C but in the same links there are some interface for C++. Or you could try PlPlot.

like image 3
Luis G. Costantini R. Avatar answered Nov 16 '22 23:11

Luis G. Costantini R.


If you're interested in soft-realtime plotting, you're probably best of using a hardware accelerated graphics api (such as OpenGL), and plotting the chart yourself.

like image 1
Arafangion Avatar answered Nov 16 '22 23:11

Arafangion