0
我試過保存png文件的代碼here,它工作。 但我想保存一個矢量圖像,所以我將終端改爲:PostscriptTerminal和SVGTerminal。對於SVGTerminal空輸出,當我使用PostscriptTerminal代碼掛在p.plot();
如何在JavaPlot中保存svg或esp文件
ImageTerminal png = new ImageTerminal();
PostscriptTerminal eps = new PostscriptTerminal();
SVGTerminal svg = new SVGTerminal();
File file = new File("D:/plot.eps");
try {
file.createNewFile();
eps.processOutput(new FileInputStream(file));
} catch (FileNotFoundException ex) {
System.err.print(ex);
} catch (IOException ex) {
System.err.print(ex);
}
PlotStyle myPlotStyle = new PlotStyle();
myPlotStyle.setStyle(Style.POINTS);
myPlotStyle.setPointType(7); // 7 - circle
myPlotStyle.setLineType(3); // blue color
JavaPlot p = new JavaPlot();
p.setPersist(false);
p.setTerminal(eps);
//p.setTitle(algorithm_name+" - "+problem_name, "Arial", 20);
p.getAxis("x").setLabel("X axis", "Arial", 15);
p.getAxis("y").setLabel("Y axis","Arial", 15);
p.setKey(JavaPlot.Key.TOP_RIGHT);
double[][] front = this.writeObjectivesToMatrix();
DataSetPlot s = new DataSetPlot(front);
s.setPlotStyle(myPlotStyle);
s.setTitle("");
p.addPlot(s);
p.plot(); //code hangs here if I use PostscriptTerminal
try {
//ImageIO.write(png.getImage(), "png", file); //works
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write (eps.getTextOutput());
//Close writer
writer.close();
} catch (IOException ex) {
System.err.print(ex);
}