Get Binary Image Data From a MatPlotLib Canvas?

后端 未结 1 993
挽巷
挽巷 2021-01-02 16:21

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 = \'         


        
相关标签:
1条回答
  • 2021-01-02 16:48

    Use a StringIO object as a file object, which can be given to the print_png canvas function.

    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)

    0 讨论(0)
提交回复
热议问题