Prophet: Getting NameError: name 'go' is not defined

Created on 29 Jul 2019  路  14Comments  路  Source: facebook/prophet

Dear Experts,

I am getting error while running in Anaconda (Window, Python Version 3). Please find my example code and error:

Example code:

from fbprophet.plot import plot_plotly as go
import plotly.offline as py
py.init_notebook_mode()

fig = plot_plotly(m, forecast) # This returns a plotly Figure
py.iplot(fig)

I am getting following error:

NameError Traceback (most recent call last)
in
3 py.init_notebook_mode()
4
----> 5 fig = plot_plotly(m, forecast) # This returns a plotly Figure
6 py.iplot(fig)

~AppDataLocalContinuumanaconda3libsite-packagesfbprophetplot.py in plot_plotly(m, fcst, uncertainty, plot_cap, trend, changepoints, changepoints_threshold, xlabel, ylabel, figsize)
560 data = []
561 # Add actual
--> 562 data.append(go.Scatter(
563 name='Actual',
564 x=m.history['ds'],

NameError: name 'go' is not defined

Kindly help me in this case.

Most helpful comment

OK, i found the solution.

Instead of creating the go object as suggested above:
import plotly.graph_objs as go (you can simply remove it)

just install ipywidgets instead, and restart the notebook:
pip install ipywidgets

...and here's what you should get (an interactive chart):
Screenshot 2019-09-17 at 23 14 33

All 14 comments

I have the same issue...

If "NameError: name 'go' is not defined" is raised, the Plotly import likely failed (installing plotly is optional, so error is not thrown if that happens). One way I could se this happening is if Plotly is installed while the kernel is running and the plots are already imported. To check if that was the case, first confirm that Plotly is installed and then start a new kernel.

(To make this clearer, there should maybe be a more descriptive error raised in Plotly functions if the import has previously failed)

You can verify if plotly is working by running this:

import plotly.graph_objs as go

I stlll get the error after importing the go object:

from fbprophet.plot import plot_plotly
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode()

fig = plot_plotly(m, forecast)  # This returns a plotly Figure
py.iplot(fig)

The error:

NameError                                 Traceback (most recent call last)
<ipython-input-165-63b7d06ac367> in <module>
      4 py.init_notebook_mode()
      5 
----> 6 fig = plot_plotly(m, forecast)  # This returns a plotly Figure
      7 py.iplot(fig)

~/.conda/envs/feas-fcst-cogo/lib/python3.7/site-packages/fbprophet/plot.py in plot_plotly(m, fcst, uncertainty, plot_cap, trend, changepoints, changepoints_threshold, xlabel, ylabel, figsize)
    560     data = []
    561     # Add actual
--> 562     data.append(go.Scatter(
    563         name='Actual',
    564         x=m.history['ds'],

NameError: name 'go' is not defined

If I include the code of the function plot_plotly from fbprophetplot.py in my notebook it works correctly. Strange.

Even i add code of fbprophetplot.py function not working for me :(

Also having the same issue.

OK, i found the solution.

Instead of creating the go object as suggested above:
import plotly.graph_objs as go (you can simply remove it)

just install ipywidgets instead, and restart the notebook:
pip install ipywidgets

...and here's what you should get (an interactive chart):
Screenshot 2019-09-17 at 23 14 33

@mprzydatek thanks for helping debug this - it looks like notebook and ipywidgets packages are both required for plotly to work in jupyter notebook (https://github.com/plotly/plotly.py). I wasn't aware of this. We should definitely put this in the documentation.

In my case, restarting the kernel solves the problem for me.

Screenshot 2020-07-20 at 9 06 32 PM
Showing no output and guess what following same steps and procedure mentioned on official documentation on same dataset https://facebook.github.io/prophet/docs/quick_start.html#python-api

@bumblebee2311 is this in a jupyter notebook? can you verify that you have the notebook and ipywidgets packages installed?

@bumblebee2311 is this in a jupyter notebook? can you verify that you have the notebook and ipywidgets packages installed?

Yes, it's in Jupiter lab notebook and I did imported ipywidgets pkg as mentioned in conversation.

Can you check if non-prophet plotly plot will show? Maybe something like this:

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

py.init_notebook_mode()

trace0 = go.Scatter(
  x=[1, 2, 3, 4],
  y=[10, 15, 13, 17]
)
data = go.Data([trace0])

py.iplot(data)

The requirements of notebook and ipywidgets were added to the quickstart doc https://facebook.github.io/prophet/docs/quick_start.html#python-api

Was this page helpful?
0 / 5 - 0 ratings