Dynamically serving a matplotlib image to the web using python

后端 未结 6 1503
悲哀的现实
悲哀的现实 2020-11-29 02:43

This question has been asked in a similar way here but the answer was way over my head (I\'m super new to python and web development) so I\'m hoping there\'s a simpler way o

6条回答
  •  佛祖请我去吃肉
    2020-11-29 03:28

    what works for me with python3 is:

    buf = io.BytesIO()
    plt.savefig(buf, format='png')
    image_base64 = base64.b64encode(buf.getvalue()).decode('utf-8').replace('\n', '')
    buf.close()
    

提交回复
热议问题