2015-02-11 15 views
0

我知道gnu圖形是一個相當不錯的工具,並且有很多功能,但我只需要它繪製一個簡單的X和Y圖形,並提供數據值通過從C程序管道需要幫助繪製使用gnuplot通過C管道的最簡單的x,y圖形

在這裏,我寫了一個簡單的程序來繪製一些價值,它在一些系統中工作正常,但它不是在我的工作!

是的,我確實在我的Ubuntu的安裝gnuplot的一個小時前apt-get的,還沒有圖形彈出該程序執行後,請幫我做這工作,需要的是simple..thank你

這裏是我的代碼:

#include<stdio.h> 

int main() 
{ 
FILE *p = popen("gnuplot -persist","w"); 
fprintf(p,"plot 'data.dat' with linespoints\n"); 
fprintf(p,"%d\t%d\n",100,200); 
fprintf(p,"%d\t%d\n",200,400); 
fprintf(p,"%d\t%d\n",300,600); 
fprintf(p,"e\n"); 
fclose(p); 
return 0; 
} 
+1

你想在C代碼中繪製文件'data.dat'或你傳遞給gnuplot的數字嗎? – 2015-02-11 14:14:26

+0

我想繪製我穿過管道的數字.. – 2015-02-16 12:58:32

回答

0

好了,終於讓我找到的bug,這是不符合我的計劃,但gnuplot的..

我不得不與gnuplot的 一起安裝的gnuplot-X11,所以我做了一個sudo易於得到安裝的gnuplot-X11

現在用相同的上述程序,圖形彈出明亮...

謝謝大家的幫助:)

0

您需要將數據繪製到你需要指定GNU陰謀其實情節臨時文件。將你的座標寫在臨時文件中,然後傳遞命令。

#include <stdlib.h> 
#include <stdio.h> 
#define COMMANDS 2 

int main() 
{ 
    char * commandsForGnuplot[] = {"set title \"My Little Graph\"", "plot 'data.temp'"}; 
    FILE * temp = fopen("data.temp", "w"); // write coordinates here. 
    FILE * gnuplotPipe = popen ("gnuplot -persistent", "w"); 
    int i; 
    fprintf(temp, "%lf %lf \n", 100.0, 200.0); //Write the data to a temporary file 
    fprintf(temp, "%lf %lf \n", 200.0, 400.0); 
    for (i=0; i < COMMANDS; i++) 
    { 
     fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one. 
    } 
    return 0; 
} 
0

如果我理解正確的話,你需要使用特殊的文件名「 - 」在你的「陰謀」字符串命令,它告訴GNUPLOT閱讀越過標準輸入流值:在

#include<stdio.h> 

int main() 
{  
    FILE *p = popen("gnuplot -persist","w"); 
    fprintf(p,"plot '-' with linespoints\n"); 
    fprintf(p,"%d\t%d\n",100,200); 
    fprintf(p,"%d\t%d\n",200,400); 
    fprintf(p,"%d\t%d\n",300,600); 
    fprintf(p,"e\n"); 
    fclose(p); 
    return 0; 
} 

的代碼你問題是忽略您傳遞的值並顯示文件data.dat的內容。