栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用python动态将matplotlib图像提供给网络

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用python动态将matplotlib图像提供给网络

你应该

  • 首先写入cStringIO对象
  • 然后写HTTP头
  • 然后将cStringIO的内容写入stdout

因此,如果发生错误

savefig
,您仍然可以返回其他内容,甚至另一个标头。有些错误不会更早地识别出来,例如文本问题,图像尺寸太大等。

您需要告诉

savefig
将输出写入何处。你可以做:

format = "png"sio = cStringIO.StringIO()pyplot.savefig(sio, format=format)print "Content-Type: image/%sn" % formatmsvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) # Needed this on windows, IISsys.stdout.write(sio.getvalue())

如果要将图像嵌入HTML:

print "Content-Type: text/htmln"print """<html><body>...a bunch of text and html here...<img />...more text and html...</body></html>""" % sio.getvalue().enpre("base64").strip()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/638068.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号