Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use plotly offline to generate graphs as images

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?

like image 905
Matt Cremeens Avatar asked Jan 22 '16 23:01

Matt Cremeens


People also ask

Does Plotly Express work offline?

Starting with this version, the only supported mode of operation in the plotly package is “offline” mode, which requires no internet connection, no account, no authentication tokens, and no payment of any kind.

Can you use plotly offline?

Plotly allows you to generate graphs offline and save them in local machine. The plotly. offline. plot() function creates a standalone HTML that is saved locally and opened inside your web browser.


1 Answers

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

like image 75
LordK Avatar answered Oct 27 '22 14:10

LordK