我可以在python中离线使用图地工厂吗?

时间:2018-07-17 09:46:52

标签: python jupyter-notebook plotly

我正在尝试在离线的Jupyter笔记本中以绘图方式创建甘特图,将Gantt chart tutorialoffline tutorial融合在一起,我尝试过:

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)

但这只会返回有关plotly API的错误,如果我处于离线状态,则不会发生此错误...

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

我可以离线绘制其他图表,是否可以使用图形工厂并离线绘制?

2 个答案:

答案 0 :(得分:1)

如果您plotly.offline.plot(fig),也可以使用import plotly,但是它不适用于'plotly.plotly'。

答案 1 :(得分:0)

哦,射击,这是一个非常简单的错误。

py.iplot(fig)调用plotly的在线版本,而iplot(fig)调用离线的版本。

这对我有用

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)