使用 BytesIO
show me the code:
import io import matplotlib.pyplot as plt from PIL import Image plt.figure() plt.plot([0, 1]) buf = io.BytesIO() plt.savefig(buf, format='png') buf.seek(0) //此处划重点 im = Image.open(buf) im.show() buf.close()