Nick Duddy
Nick Duddy

Reputation: 1000

Why would Plotly not recognise attribute 'offline'?

I'm following the tutorial plotly timeseries, here. I've also amended the code to allow for offline charts in Jupyter, here.

I'm trying to plot a timeseries in Jupyter Notebook. I get the following error.

AttributeError: module 'plotly.plotly' has no attribute 'offline'

As far as I can see I've carried out all the instructions but can't get it to work with the method they suggest.

import plotly.plotly as py
import plotly.graph_objs as go

py.offline.init_notebook_mode()

data = [go.Scatter(x=dataload.date, y=dataload.spend)]

py.offline.iplot(data)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-c9b2e8d8907c> in <module>()
      2 import plotly.graph_objs as go
      3 
----> 4 py.offline.init_notebook_mode()
      5 
      6 data = [go.Scatter(x=dataload.date, y=dataload.spend)]

AttributeError: module 'plotly.plotly' has no attribute 'offline'

Does anyone have a suggestion to why I might be getting this error, could it be a local setup issue?

Upvotes: 6

Views: 8315

Answers (1)

Sayali Sonawane
Sayali Sonawane

Reputation: 12599

Just use:

 import plotly
 plotly.offline.init_notebook_mode()

don't use: import plotly.plotly as py

You are referring different documentation. Use https://plot.ly/python/getting-started/#initialization-for-offline-plotting Here it also provides more information regarding how to use help function.

For tutorial in offline mode: https://github.com/SayaliSonawane/Plotly_Offline_Python

Upvotes: 7

Related Questions