JavaPlot和gnuplot [英] JavaPlot and gnuplot

查看:236
本文介绍了JavaPlot和gnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拼命想让Java和gnuplot发挥得更好。我已经开始使用 JavaPlot 并将jar添加到类路径中(使用Eclipse)。

I'm desperately trying to get Java and gnuplot to play nice. I've started using JavaPlot and have added the jar to the classpath (using Eclipse).

我还下载了gnuplot,并把它放在一个安全的地方。

I've also downloaded gnuplot and have placed it in a safe place.

第一个问题, JavaPlot 给出的所有例子都假设您已将gnuplot放在正确的位置,这是我不知道。因此他们的例子是:

First question, all examples given by JavaPlot are assuming you have put gnuplot in the right place, where this is I have no idea. Therefore their example of:

import com.panayotis.gnuplot.JavaPlot;

public class test {
    public static void main(String[] args) {
        JavaPlot p = new JavaPlot();
        p.addPlot("sin(x)");
        p.plot();
    }
}

只有将gnuplot添加到类路径中才会起作用,关于它可能在哪里以及如何的任何想法?

Will only work if gnuplot is added to the classpath, any ideas on where that might be and how?

不过不用担心,因为你可以在JavaPlot的构造函数中定义gnuplot的位置,如下所示:

Not to worry though, as you can define the location of gnuplot in the constructor of JavaPlot, like so:

import com.panayotis.gnuplot.JavaPlot;

public class test {
    public static void main(String[] args) {
        JavaPlot p = new JavaPlot("D:/Eclipse/gnuplot/binary/pgnuplot.exe");
        p.addPlot("sin(x)");
        p.plot();
    }
}

如果你很快就能做到这一点看到图表出现(正确,可以看到正弦波),然后立即消失。我在网上看到,在实际的gnuplot应用程序中,这在使用Windows时很常见,并且必须在绘图后添加-persist。幸运的是, JavaPlot 也有一个函数:

This does something, if you're quick you can see a graph appear (correctly, can see the sine wave) and then immediately disappear. I've read online that in the actual gnuplot application this is common when using Windows and that a '-persist' must be added after the plot. Fortunately JavaPlot also has a function that does that:

p.setPersist(true);

但在我的情况下,它什么也没做。所以第二个问题,任何人之前都使用过gnuplot, JavaPlot 和Windows 7 64bit,并知道如何做到这一点?从我的谷歌搜索我了解pgnuplot是正确的.exe运行?

But in my case it does nothing. So second question, anyone used gnuplot, JavaPlot, and Windows 7 64bit before and know how to do this? From my Googling I understand pgnuplot is the correct .exe to run?

我缺少什么?我做错了什么?

What am I missing? What am I doing wrong?

推荐答案

我想我可能有一个解决方法,因为我碰到了同样的事情今天在Windows 7上访问JavaPlot时(虽然这里是32位)。是的,pgnuplot.exe是您想要的,但是如果您不想,则不需要显式setPersist,因为JavaPlot会为您执行此操作。我要做的就是浏览源代码并注释掉一行。

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.

在GnuPlotParameters中,我看到代码

In GnuPlotParameters, I see the code

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

这是第198-199行。然后情节窗口保持打开状态。现在,这也是做开放gnuplot。如果您不介意,可以通过这种方式查看图表。还没弄清楚如何在打开情节窗口的同时关闭gnuplot。

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.

编辑:

也许更合适的方法是不要评论第199行并使用它:

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.

这篇关于JavaPlot和gnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆