Nicholas
Nicholas

Reputation: 3737

Save Plotly Offline image in Jupyter Notebook?

I have some code that I am plotting in Jupyter Notebook, and all I am trying to do is save the image as a PNG so I can use it as a high DPI image in some work I am doing:

data = [trace1, trace2]
layout = {"title": "", 
          "xaxis": {"title": "", }, 
          "yaxis": {"title": ""}}

fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)

I cannot figure out how to save it as a PNG file, and specifically save it as a PNG file in my Jupyter Notebook folder.

I have tried the solution found here: How to save Plotly Offline graph in format png?

But I am not sure where to put the code, as my plotly plotting code is different. Everything I do ends up in an error. Any suggestions?

Upvotes: 3

Views: 5398

Answers (1)

Sheldore
Sheldore

Reputation: 39052

Try the following by providing the filename argument to iplot

plotly.offline.iplot(fig, filename='filename.png')

From the docs

Signature: plotly.offline.iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True, image=None, filename='plot_image', image_width=800, image_height=600, config=None)

Also make sure that the Trust button on upper-right of your notebook shows Trusted. If it is not, click on Not Trusted it to make it.

the "not trusted" vs "trusted" toggle button in upper-right of Jupyter notebook

Upvotes: 5

Related Questions