使用 plotly 离线生成图形作为图像 [英] Use plotly offline to generate graphs as images

查看:25
本文介绍了使用 plotly 离线生成图形作为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在离线使用 plotly 并且能够使用生成 html 文件

I am working with plotly offline and am able to generate an html file using

plotly.offline.plot({"data": data, "layout": layout})

效果很好.该图已正确生成,并且 html 文件被保存到我的当前目录中.

It works great. The graph is generated correctly and the html file gets saved to my current directory.

不过,我想要的是,使用 plotly 离线保存一个图像(.png、.jpg 等)文件.我在正确的轨道上吗?我需要从这里做什么?

What I want, though is, using plotly offline, is to have an image (.png, .jpg, etc.) file saved instead. Am I on the right track? What do I need to do from here?

推荐答案

试试这个

import plotly.offline
import plotly.graph_objs as go

plotly.offline.plot({"data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
                     "layout": go.Layout(title="hello world")},
                     image='jpeg', image_filename='test')

在 Chrome 中打开

and open it in Chrome

这篇关于使用 plotly 离线生成图形作为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆