0
votes

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?

1
You're entering a world of pain but here's a way in stackoverflow.com/questions/3521209/… - downhillFromHere
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

1 Answers

1
votes

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;
}