微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Java 上运行 gnuplot

如何解决在 Java 上运行 gnuplot

我正在运行一个使用 gnuplot 生成 pdf 图表的 Java 项目,但我想将这些文件保存在我的工作目录之外的另一个文件夹中。这可能吗?

我现在有这个

Process proc = Runtime.getRuntime().exec("gnuplot test.gp");
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(proc.getInputStream()));

        String line = "";
        while ((line = reader.readLine()) != null) {
            System.out.print(line + "\n");
        }

        proc.waitFor();

解决方法

在 gnuplot 控制台中检查 help command line options。有选项 -e

您需要在 Java 中为 exec() 提供以下参数。

"gnuplot -e myOutput='<YourPDF>' test.gp"

您必须将 <YourPDF> 替换为您的路径。由于我不懂 Java,Java 人员必须告诉您如何完成此操作。

一个最小的 gnuplot 脚本如下所示:

set term pdfcairo
set output myOutput
plot sin(x)   # or whatever
set output

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。