import io from PIL import Image def fig2img(fig): buf = io.BytesIO() fig.savefig(buf) buf.seek(0) return Image.open(buf)