如何在C程序中使用gnuplot绘制图形

如何在C程序中使用gnuplot绘制图形,c,graph,gnuplot,C,Graph,Gnuplot,我正试图从C程序(Windows7)中绘制一个图形 我维护了一个图形点数组,比如x[]和y1[],y2[]和y3[]。我想为固定的x点绘制多个y点。 如何从程序中使用gnuplot绘制图形?不是最优雅的解决方案,但这应该可以: int main(int argc, char **argv){ FILE * temp = fopen("data.temp", "w"); FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");

我正试图从C程序(Windows7)中绘制一个图形 我维护了一个图形点数组,比如x[]和y1[],y2[]和y3[]。我想为固定的x点绘制多个y点。
如何从程序中使用gnuplot绘制图形?

不是最优雅的解决方案,但这应该可以:

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;
}
或者,您可以执行以下操作:

int plot(){
    system("gnuplot -p -e \"(Here put whatever you would put in gnuplot as if you were ploting manually)\"");
    return 0;
}

你正在进入一个痛苦的世界,但这里有一个方法,我尝试使用上面链接中的代码示例。但管道似乎不适用于Windows系统。一旦我运行程序,它会打开一个输出窗口,但不会显示任何绘图。