我试图在浏览器上显示matlib绘图,我使用的是Django。到目前为止,我已经:
import matplotlib.pyplot as plt
import base64
from io import BytesIO
fig = plt.figure()
#plot sth
tmpfile = BytesIO()
fig.savefig(tmpfile, format='png')
encoded = base64.b64encode(tmpfile.getvalue())
html = 'Some html head' + '<img src=\'data:image/png;base64,{}\'>'.format(encoded) + 'Some more html'
with open('test.html','w') as f:
f.write(html)
但是,我想要的不是f.write(html),而是:
return render_to_response(html)
如何处理一个大的html字符串?你知道吗
你试过HttpResponse吗?你知道吗
我是用这个库得到的:https://mpld3.github.io/quickstart.html
以及空白.html看起来像这样:
相关问题 更多 >
编程相关推荐