I'm trying to get the binary data from a matplotlib canvas so I can attach it to an email, but the only way I've found to do so is by saying:
filename = 'image.png'
canvas.print_figure(filename)
with open(filename, 'rb') as image:
return image.read()
I'd really like to avoid the Disk IO since I don't need to hold onto the file afterwards.