I am attempting to use the pipe interface to gnuplot (a standard one gnuplot_i.{cpp,hpp}) in order to generate a real time display of values that are continually changing within another program written in C++. This works ok but I wanted to see if anyone had any suggestions for improvement.
This implementation contains a convenience method to plot a single vector and 2 vectors as a 2D plot. It achieved this by writing out to a temporary file via a standard library call to the mktemp function and then using that as input to a gnuplot plot call. This generated too many temporary files and didn't appear to work well when the update rate on the plot is high (maybe IO limited at a point). I have decided to use the '-' pseudo file in the plot call and just send the vectors directly to the pipe (ended with a single line with "e" on it). This works better but is still not great.
Is there a slicker way to do what I am attempting to do than to continually regenerate the plot when the values have changed? How often is it safe to update the plot with new information? Alternatively, maybe there's a much simpler way to achieve what I am trying to do?
I have no "requirements" per se. What I meant by slick was that maybe there was a more elegant approach to doing what I was attempting while still using gnuplot. Although elegant is subjective, I find the approach I am presently taking particularly inelegant. What I meant by safe was whether anyone knew at what update rate there would be IO problems (e.g., latency, lock-up of display, etc.) with said approach.
I'd like to avoid using a toolkit for the following reasons (my short-list at least).
However, if you have any particular suggestions in terms of C/C++ plotting libraries that seem like a good fit given the above list I am always interested in suggestions (warning: I have already looked around a good bit to find them).
gnuplot-cpp is an object-oriented C++ wrapper interface around a POSIX pipe connection with Gnuplot.
The example file compiled right away and the interfacing code looks decent; I'll be trying it in my current project.
there is a C2gnuplot library I wrote few years ago. It is very simple but may give you some tips. Basically it uses FIFO files to pass data into Gnuplot.It is able to generate animation from the plots. Here is a video created with the app. I hope this will be useful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With