Use plotly offline to generate graphs as images

Matt Cremeens picture Matt Cremeens · Jan 23, 2016 · Viewed 26.6k times · Source

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

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

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

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?

Answer

LordK picture LordK · Mar 12, 2017

Try this

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')

and open it in Chrome