haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
6k stars 1.12k forks source link

Support save to image in smile-plot #779

Closed wwulfric closed 1 month ago

wwulfric commented 1 month ago

Is your feature request related to a problem? Please describe.

I wanna plot and save it to a image file, then send it

Describe the solution you'd like View could have a save method.

haifengl commented 1 month ago

import java.awt.Color; import smile.io.; import smile.plot.swing.; import org.apache.commons.csv.CSVFormat;

var toy = Read.csv("data/classification/toy200.txt", CSVFormat.DEFAULT.withDelimiter('\t'));
var canvas = ScatterPlot.of(toy, "V2", "V3", "V1", '.').canvas();
var image = canvas.toBufferedImage(400, 400);
javax.imageio.ImageIO.write(image, "png", new java.io.File("headless.png"));
haifengl commented 1 month ago

BTW, this was covered in the FAQ of smile website.