plotly.py: Offline mode not displaying inline in Jupyter notebook master?

I hadn’t tested recently, but today, using master of the Jupyter notebook, I can’t get offline plots to display inline, instead I get the external temporary file. Consider this simple test:

from plotly import __version__
from plotly.offline import init_notebook_mode, plot
from plotly.graph_objs import Scatter

init_notebook_mode()

print("plotly version:", __version__)
plot([Scatter(x=[1, 2, 3], y=[3, 1, 6])])

I get for output:

plotly version: 1.9.10
Out[1]: 'file:///Users/fperez/tmp/temp-plot.html'

and the plot correctly opening in a new tab by itself, but no inline notebook output. Here’s a screenshot for reference:

image

In the JS console, I don’t see anything that immediately points to the problem. Here’s a screenshot, b/c copy-pasting text from the JS console makes a mish-mash of the formatting:

image

The above were from current Chrome on OSX, but I replicated the problem on Safari.

Any thoughts on how to proceed much appreciated. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 41 (3 by maintainers)

Most upvoted comments

@edoson

Oddly, this only occurs for me in Notebooks with very high memory usage (10+ GB) and LOTs of plots. I have found, for whatever reason, that running the Notebook cell-by-cell also helps (as opposed to “Restart and Run All”).

Here’s the steps I use:

  1. Open Notebook (might have been saved with plots there);

  2. Restart and Clear Output;

  3. Save the Notebook;

  4. Hard Refresh of browser;

  5. Run Notebook cell-by-cell.

In newer jupyter versions, the requirejs error might be because of notebook trust. When the notebook considers the .ipynb untrusted, it will not run javascript on initialization. This interferes with the way that plotly gets injected into the jupyter notebook.

If that is the issue, clicking the button in the top right of the notebook to “trust” the ipynb may fix it. Installing & configuring the nbextension might help too.

Hi there - can you try using iplot() instead of plot . plot should return a div or html file while iplot() will plot in your notebook Here’s a reference: https://plot.ly/python/offline/

Adding plotly.offline.init_notebook_mode() solved this problem for me.

It would be helpful to know, for the people who are seeing this problem, what is the state of the Trust indicator in the top right hand corner. Is this happening for Trusted notebooks, or only non-trusted notebooks (as my theory would have it)?

nbtrust

still blank plot after try every ways

In case this issue is still coming up in google searches, please check out the new FigureWidget support for Jupyter 😸 https://medium.com/@plotlygraphs/introducing-plotly-py-3-0-0-7bb1333f69c6

Save the notebook and refresh browser solved the problem for me.

@thhancock @edoson Starting with the version 5.0 the Jupyter Notebook has a limited data_rate. Read here https://community.plot.ly/t/tips-for-using-plotly-with-jupyter-notebook-5-0-the-latest-version/4156 how to increase this rate.

@edoson

Hard reset seems to be working for me too. CTRL + F5 on Windows with Chrome.

Was this ever figured out? Sometimes it works for me and sometimes it doesn’t so it’s difficult to use plotly consistently.

import plotly
import plotly.offline as py
from plotly import graph_objs as go
py.init_notebook_mode(connected=True)
print(plotly.__version__)
# 2.0.6

# Simple sine function
x = np.linspace(0,2*np.pi)
y = np.sin(x)
trace = go.Scatter(x=x,y=y)
py.iplot([trace])

I’m using Python 3.6 but I also had this issue with 3.5.2. Jupyter version is jupyter 1.0.0 py36_3 and IPython 5.1.0

image A hard refresh of the notebook in the browser (Ctrl+Shift+r) solves this.

Update -

I’ve updated jupyter, ipython, plotly and cuffilnks to latest versions and hard refresshed my notebook (shift + command + r on my mac) and the plots are back.