I have written a program which writes a list of data to a ‘.dat’ file with the intention of then plotting it separately using gnuplot. Is there a way of making my code plot it automatically? My output is of the form:
x-coord analytic approximation
x-coord analytic approximation
x-coord analytic approximation
x-coord analytic approximation
x-coord analytic approximation
....
Ideally, when I run the code the graph would also be printed with an x-label, y-label and title (which could be changed from my C code). Many thanks.
I came across this while searching for something else regarding gnuplot. Even though it’s an old question, I thought I’d contribute some sample code. I use this for a program of mine, and I think it does a pretty tidy job. AFAIK, this PIPEing only works on Unix systems (see the edit below for Windows users). My gnuplot installation is the default install from the Ubuntu repository.
EDIT
In my application, I also ran into the problem that the plot doesn’t appear until the calling program is closed. To get around this, add a
fflush(gnuplotPipe)after you’ve usedfprintfto send it your final command.I’ve also seen that Windows users may use
_popenin place ofpopen— however I can’t confirm this as I don’t have Windows installed.EDIT 2
One can avoid having to write to a file by sending gnuplot the
plot '-'command followed by data points followed by the letter “e”.e.g.