I am trying to plot a graph from within C program (Windows 7) I have maintained an array of graph points,say x[] and y1[],y2[] and y3[]. I want to plot multiple y points for fixed x points. How can I use gnuplot from within my program to plot the graph?
Asked
Active
Viewed 7,210 times
1
-
You're entering a world of pain but here's a way in http://stackoverflow.com/questions/3521209/making-c-code-plot-a-graph-automatically – downhillFromHere Oct 06 '14 at 15:03
-
I have tried using the code sample from the link above. But it seems that the piping is not working for Windows system. Once I run the program,it opens an output window but no plots appear. – SvckG Oct 06 '14 at 15:15
1 Answers
2
Not the most elegant solution, but this should work:
int main(int argc, char **argv){
FILE * temp = fopen("data.temp", "w");
FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
for(Iterate over your array so that you create another exact temporal array){
float a, b, c;
x = something;
y1 = something;
y2 = something;
y3 = something;
fprintf(temp, "%d %d %d %d \n", x, y1, y2, y3);
}
fprintf(gnuplotPipe, "(here whatever you want to tell gnuplot to do) i.e plot 'data.temp' using 1:2 with lines, etc");
return 0;
}
Alternatively you can do this:
int plot(){
system("gnuplot -p -e \"(Here put whatever you would put in gnuplot as if you were ploting manually)\"");
return 0;
}

ca_san
- 183
- 2
- 11