我试图在C程序中绘制图表(Windows 7) 我维护了一个图形点数组,比如x []和y1 [],y2 []和y3 []。我想为固定的x点绘制多个y点。 如何在我的程序中使用gnuplot绘制图形?
答案 0 :(得分:0)
不是最优雅的解决方案,但这应该有效:
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;
}