JavaPlot and gnuplot

我是研究僧i 提交于 2019-12-06 05:39:55
demongolem

I think I may have a workaround for you, as I ran into the same sort of thing today when accessing JavaPlot on Windows 7 (32 bit here though). Yes, pgnuplot.exe is the one you want, however you do not need to explicitly setPersist if you do not want to because JavaPlot does that for you. What I had to do was go through the source code and comment out a line.

In GnuPlotParameters, I see the code

/* Finish! */
bf.append("quit").append(NL);

This is lines 198-199. Then the plot windows stays open. Now, what this also does is leave open gnuplot. If you do not mind, you can see your graphs this way. Have not figured out yet how to close gnuplot while leaving the plot window open.

EDIT:

Maybe a more appropriate way is not to comment out line 199 and go with this:

bf.append("pause -1").append(NL);

/* Finish! */
bf.append("quit").append(NL);

In this manner, the pause dialog comes up. This allows you to see the plot. When you dismiss the dialog, everything goes bye-bye.

Try JavaGnuplotHybrid: https://github.com/mleoking/JavaGnuplotHybrid

It solves the problem of immediately disappear.

Here is the example for a 2D plot:

public void plot2d() {
    JGnuplot jg = new JGnuplot();
    Plot plot = new Plot("") {
        {
            xlabel = "x";
            ylabel = "y";
        }
    };
    double[] x = { 1, 2, 3, 4, 5 }, y1 = { 2, 4, 6, 8, 10 }, y2 = { 3, 6, 9, 12, 15 };
    DataTableSet dts = plot.addNewDataTableSet("2D Plot");
    dts.addNewDataTable("y=2x", x, y1);
    dts.addNewDataTable("y=3x", x, y2);
    jg.execute(plot, jg.plot2d);
}

Kelly Stanton

I use eclipse for debugging and happen to be using this package. I figured out how to fix this. Add the following to your code. The setPersist(true) doesn't seem to work for some reason.

p.set("term", "x11 persist");
user2160143

try this

try {
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("D:/Projet/X-Gnuplot_4.6.0_rev6/Bin/gnuplot/bin/gnuplot.exe");

    java.io.OutputStream opStream = proc.getOutputStream();
    PrintWriter gp = new PrintWriter(new BufferedWriter(new OutputStreamWriter(opStream)));
    gp.println("plot sin(x); pause mouse close;\n");  
    gp.close();

    int exitVal = proc.waitFor();
    System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
    System.out.println(e.toString());
    e.printStackTrace();
}

it works for me

replace your

p.addPlot("sin(x)");

by

p.addPlot("sin(x); pause 100;");

it only appears for 100 seconds fsd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!