plot.ly offline mode in jupyter lab not displaying plots

clstaudt picture clstaudt · Jan 6, 2019 · Viewed 15.7k times · Source

According to the documentation, offline mode with plot.ly in Jupyter is supposed to work after calling:

from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
init_notebook_mode(connected=True)

Now I am trying to show the following plot:

trace0 = plotly.graph_objs.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = plotly.graph_objs.Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)

iplot([trace0, trace1])

The result is much empty space in the cell output area.

enter image description here

Why is this not working with Jupyter Lab?

Answer

Lucas Durand picture Lucas Durand · Jan 7, 2019

A couple things might be happening. For some reason is your Notebook "Not Trusted?" This will stop the Plotly javascript from rendering anything below.

Another possibility is that you don't have the Plotly extension installed for Jupyter Lab. In Lab, as compared to Notebooks, there are a lot more restrictions on what javascript can execute, so packages need to have extensions installed in order to display anything beneath the cell.

Look for the plotly-extension with jupyter labextension list

and install it if missing with: jupyter labextension install @jupyterlab/plotly-extension