使用C#在GNU PLOT中绘制图形

时间:2013-06-10 07:15:27

标签: c# gnuplot

我有一个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.dat位于gnuplot的当前目录中。我希望绘制insert.dat个文件数据。

1 个答案:

答案 0 :(得分:2)

问题似乎是 gnuplot 无法找到所请求的文件。该进程的工作目录未设置为 gnuplot 目录,但可能设置为调用 gnuplot 的应用程序的目录。

编辑尝试在extPro.Start()命令之前的某处向代码中添加以下任一行:

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

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

如果这不起作用,可能是因为您的应用程序没有对该目录的读取权限。尝试将 insert.dat 文件放在任何客户端应用程序都可以访问的目录中。

顺便说一句,我也不认识你正在使用的Standardization属性?那条线应该是:

extPro.StartInfo.RedirectStandardInput = true;