code: public void save(File file) throws IOException {
          BufferedImage bi = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_ARGB);
          Graphics2D g2d = bi.createGraphics();
          canvas.print(g2d);
  
          ImageIO.write(bi, FileChooser.getExtension(file), file);
      }
docs: Exports the plot to an image file.
  @param file the destination file.
  @throws IOException if an error occurs during writing.