haifengl / smile

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

Support save to image in smile-plot #779

Closed wwulfric closed 3 months ago

wwulfric commented 4 months 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 4 months 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 3 months ago

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