Skip to content Skip to sidebar Skip to footer

How To Save Plotly Offline By Running My Script

I am using below code in my jupyter notebook. import pandas as pd import numpy as np %matplotlib inline from plotly import __version__ from plotly.offline import download_plotlyjs

Solution 1:

The Plotly graphs are generated in HTML+Javascript. When you run in Jupyter Notebook, you're in a web application that runs in the browser already, so it can render them directly.

When running on the command line, it can generate an HTML file with the graph for you, but you'll need to open that in the browser to have it rendered.

The Plotly Offline documentation page explains this. The text there says that you can save images only when running in Notebook. There seems to be a way to generate an image using online mode - you will need a Plotly account and network access for that.

You might want to consider a different plot library for automated offline work, which does not require network access or running an HTML user agent.

Solution 2:

tried this https://plot.ly/python/static-image-export/ and volla!

though I had to struggle with orca.

import pandas as pd
import numpy as np

%matplotlib inline

from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
import plotly.io as pio


print(__version__)

import cufflinks as cf
init_notebook_mode(connected=True)
cf.go_offline()


fig = go.Figure()
fig.add_bar(x=df2['Category'],y=df2['Values'])

iplot(fig)
pio.write_image(fig, 'fig1.png')

Post a Comment for "How To Save Plotly Offline By Running My Script"