Returning Matplotlib image as string

前端 未结 4 1908
天命终不由人
天命终不由人 2020-12-31 12:14

I am using matplotlib in a django app and would like to directly return the rendered image. So far I can go plt.savefig(...), then return the location of the im

4条回答
  •  -上瘾入骨i
    2020-12-31 12:41

    what about cStringIO?

    import pylab
    import cStringIO
    pylab.plot([3,7,2,1])
    output = cStringIO.StringIO()
    pylab.savefig('test.png', dpi=75)
    pylab.savefig(output, dpi=75)
    print output.getvalue() == open('test.png', 'rb').read() # True
    

提交回复
热议问题