Unable to save Gnuplot png from within c#

2020-07-24 06:06发布

问题:

im trying to open gnuplot from within c# and get it to save a png of a chart. There are 2 issues im having

1) both a black commandline box for gnuplot and the actual plot appear. I would like both of these to not appear.

2) After setting the terminal to png and plotting sin(x) it doesnt actually save the file. These same commands work within gnuplot though.

Any tips would be appreciated

Thanks

    private void button1_Click(object sender, EventArgs e)
    {
        string Pgm = @"C:\Program Files\gnuplot\bin\gnuplot.exe";
        Process extPro = new Process();
        extPro.StartInfo.FileName = Pgm;
        extPro.StartInfo.UseShellExecute = false;
        extPro.StartInfo.RedirectStandardInput = true;
        extPro.Start();

        StreamWriter gnupStWr = extPro.StandardInput;

        gnupStWr.WriteLine("Set terminal png");
        gnupStWr.WriteLine(@"set output 'c:\Users\FrazMan\Desktop\sinxplot2.png'");
        gnupStWr.WriteLine("plot sin(x)");
        gnupStWr.WriteLine("set terminal wxt enhanced");
        gnupStWr.WriteLine("set output");
        gnupStWr.Flush();
    }

回答1:

seems to me that you could have a problem with your script for the GNUPLOT

Try something simpler

I think the following script should work

gnupStWr.WriteLine("set terminal png");
gnupStWr.WriteLine(@"set output 'c:\Users\FrazMan\Desktop\sinxplot2.png'");
gnupStWr.WriteLine("plot sin(x)");

Try to avoid capital letters for "set terminal png"

I hope it will help you