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 = \'
Use a StringIO object as a file object, which can be given to the print_png canvas function.
StringIO
print_png
from cStringIO import StringIO sio = StringIO() canvas.print_png(sio) return sio.getvalue()
(if you're using Python 3, use io.BytesIO instead of cStringIO)
io.BytesIO
cStringIO