簡體   English   中英

使用C#在GNU PLOT中繪制圖形

[英]Plotting graph in GNU PLOT using C#

我有一個dat文件insert.dat

內容如下:

1000    0.002322044 0.00291182
5000    0.000103257 0.000458963
10000   2.50E-05    0.000172019
20000   6.18E-06    6.03E-05
40000   2.51E-06    2.65E-05
60000   1.65E-06    1.71E-05
80000   1.21E-06    1.23E-05
100000  1.01E-06    9.97E-06

當我打開gnuplot.exe並鍵入帶有行的plot insert.dat時,會得到正確的輸出,但是當我編寫C#代碼時,如下所示:

private  void GNUPlot()
{
    string pgm = @"E:\gnuplot\bin\gnuplot.exe";

    Process extPro = new Process();
    extPro.StartInfo.FileName = pgm;
    extPro.StartInfo.UseShellExecute = false;
    extPro.StartInfo.Standardization = true;
    extPro.Start();

    StreamWriter gnupStWr = extPro.StandardInput;
    gnupStWr.WriteLine("plot \"insert.dat\" with lines ");
    gnupStWr.Flush();
}

我收到以下警告:

warning: Skipping unreadable file "insert.dat"

當我更換

gnupStWr.WriteLine("plot \"insert.dat\" with lines ");

gnupStWr.WriteLine("plot sin(x) ");

我得到所需的Sin(x)圖輸出。

insert.datgnuplot的當前目錄中。 我想繪制insert.dat文件數據。

問題似乎是gnuplot找不到所需的文件。 進程的工作目錄未設置為gnuplot目錄,但可能設置為正在調用gnuplot的應用程序的目錄。

編輯嘗試extPro.Start()添加到extPro.Start()命令之前的代碼中:

extPro.StartInfo.WorkingDirectory = @"E:\gnuplot\bin";

要么

Environment.CurrentDirectory = @"E:\gnuplot\bin";

如果這不起作用,則可能是因為您的應用程序對該目錄沒有讀取權限。 嘗試將您的insert.dat文件放在任何客戶端應用程序都可以肯定地訪問的目錄中。

順便說一句,我也無法識別您正在使用的Standardization屬性? 該行應改為:

extPro.StartInfo.RedirectStandardInput = true;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM