使用 plotly 离线生成图形作为图像离线、图形、图像、plotly

2023-09-06 07:19:22 作者:你不懂我我不怪你

我正在离线使用 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