edge-case
edge-case

Reputation: 1334

Can I use plotly figure factory offline in python?

I'm trying to create a gantt chart with plotly in an offline Jupyter notebook, mashing together the Gantt chart tutorial and the offline tutorial, I tried this:

import plotly.plotly as py
import plotly.figure_factory as ff
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

init_notebook_mode(connected=True)

dfoo = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
      dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
      dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]
fig = ff.create_gantt(dfoo)
py.iplot(fig)

But this only returns an error about the plotly API, which shouldn't happen if I'm offline...

PlotlyRequestError: Aw, snap! You tried to use our API as the user ___, but the supplied API key doesn't match our records. 

I can plot other charts offline, is there a way to use figure factory and plot offline?

Upvotes: 1

Views: 1422

Answers (2)

derhannes
derhannes

Reputation: 21

You can also use plotly.offline.plot(fig) if you import plotly, it doesn't work for 'plotly.plotly' though.

Upvotes: 1

edge-case
edge-case

Reputation: 1334

Oh, shoot, it was a very simple mistake.

py.iplot(fig) calls the online version of plotly while iplot(fig) calls the offline version.

This works for me

dfoo = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
      dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
      dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]
fig = ff.create_gantt(dfoo)
iplot(fig)

Upvotes: 0

Related Questions