如何在JavaPlot中输出png文件

编程入门 行业动态 更新时间:2024-10-26 15:17:56
本文介绍了如何在JavaPlot中输出png文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用> gnujavaplot,但没有找到制作输出图像文件的方法.我只是在gnuplot窗口中绘图,我需要在png文件中输出绘图.

i using ">gnujavaplot and i not found a way to make outputs image files. I just plot in gnuplot window, i need the plot output in png file.

我需要类似的东西: $设置终端png $设置输出"filename.png" 在gnujavaplot中.

I need something like: $ a set terminal png $ set output "filename.png" in gnujavaplot.

谢谢.

推荐答案

我只是复制了我的实际代码,没有进行任何编辑,所以有一些开销,但是我认为您应该有所作为.有趣的部分始于

i just copy my actual code, withoout editing, so there is a few overhead, but i think you should get the thing. The interesting part starts at

ImageTerminal png = new ImageTerminal();

不要错过代码的结尾!

问候

import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import javax.imageio.ImageIO; import com.panayotis.gnuplot.JavaPlot; import com.panayotis.gnuplot.plot.DataSetPlot; import com.panayotis.gnuplot.style.NamedPlotColor; import com.panayotis.gnuplot.style.PlotStyle; import com.panayotis.gnuplot.style.Style; import com.panayotis.gnuplot.terminal.ImageTerminal; public class main { public static void main(String[] args) { double[][] values = new double[3][2]; values[0][0] = 0.1; values[0][1] = 0.3; values[1][0] = 0.4; values[1][1] = 0.3; values[2][0] = 0.5; values[2][1] = 0.5; double[][] values2 = new double[3][2]; values2[0][0] = 0.2; values2[0][1] = 0.0; values2[1][0] = 0.7; values2[1][1] = 0.1; values2[2][0] = 0.6; values2[2][1] = 0.5; PlotStyle styleDeleted = new PlotStyle(); styleDeleted.setStyle(Style.POINTS); styleDeleted.setLineType(NamedPlotColor.GRAY80); PlotStyle styleExist = new PlotStyle(); styleExist.setStyle(Style.POINTS); styleExist.setLineType(NamedPlotColor.BLACK); DataSetPlot setDeleted = new DataSetPlot(values); setDeleted.setPlotStyle(styleDeleted); setDeleted.setTitle("deleted EMs"); DataSetPlot setExist = new DataSetPlot(values2); setExist.setPlotStyle(styleExist); setExist.setTitle("remaining EMs"); ImageTerminal png = new ImageTerminal(); File file = new File("/home/testuser/plot.png"); try { file.createNewFile(); png.processOutput(new FileInputStream(file)); } catch (FileNotFoundException ex) { System.err.print(ex); } catch (IOException ex) { System.err.print(ex); } JavaPlot p = new JavaPlot(); p.setTerminal(png); p.getAxis("x").setLabel("yield"); p.getAxis("y").setLabel("biomass"); p.getAxis("x").setBoundaries(0.0, 1.0); p.getAxis("y").setBoundaries(0.0, 1.0); p.addPlot(setDeleted); p.addPlot(setExist); p.setTitle("remaining EMs"); p.plot(); try { ImageIO.write(png.getImage(), "png", file); } catch (IOException ex) { System.err.print(ex); } }

}

更多推荐

如何在JavaPlot中输出png文件

本文发布于:2023-07-27 00:24:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   如何在   JavaPlot   png

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!