1

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?

2
  • You're entering a world of pain but here's a way in stackoverflow.com/questions/3521209/… Commented Oct 6, 2014 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. Commented Oct 6, 2014 at 15:15

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.