6👍
✅
I think you have to pass buff
to ImageReader
somehow.
I’m using this function to save and draw the figures I generate with matplotlib
and it works perfectly for me.
seek(offset, whence=SEEK_SET)
Change the stream position to the given offset. Behaviour depends on the whence parameter. The default value for whence is SEEK_SET.
getvalue()
doesn’t work except the seek(0)
def save_and_draw(fig, x_img, y_img, width_img=width_img, height_img=height_img):
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0)
imgdata = ImageReader(imgdata)
self.c.drawImage(imgdata, x_img, y_img, width_img, height_img)
plt.close(fig)
Source:stackexchange.com