def do_clip(self): buf = io.BytesIO() self.fig.savefig(buf) QApplication.clipboard().setImage(QImage.fromData(buf.getvalue())) buf.close()