2014-10-06 43 views
0

我想繪製從C程序(Windows 7)內的圖形 我已經維護了一個圖點的數組,例如x []和y1 [],y2 [ ]和y3 []。我想繪製固定x點的多個y點。 如何從我的程序中使用gnuplot來繪製圖形?如何從C程序中使用gnuplot來繪圖

+0

你進入一個痛苦的世界,但這裏是在HTTP的方式:/ /stackoverflow.com/questions/3521209/making-c-code-plot-a-graph-automatically – downhillFromHere 2014-10-06 15:03:24

+0

我曾嘗試使用上述鏈接的代碼示例。但似乎管道不適用於Windows系統。一旦我運行該程序,它會打開一個輸出窗口,但不會出現任何圖形。 – SvckG 2014-10-06 15:15:55

回答

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