Soerendip
Soerendip

Reputation: 9138

How to show Plotly figures in JupyterLab 3+?

I am running JupyterLab 3.0.6 and Plotly 4.14.1. It seems all the plotly dash plugins are outdated? Is there any extension that works with JupyterLab 3 yet?

E.g.

import plotly.express as px
px.line([1,2,3,2])

Only shows an empty output.

Upvotes: 6

Views: 5550

Answers (6)

Curtis ZZZ
Curtis ZZZ

Reputation: 1

As described by @piedpiper in https://stackoverflow.com/a/77320500/23203605, pio.renderers.default is the key in my JupyterLab 3 setup.

This fixed my problem:

import plotly.io as pio
pio.renderers.default = 'iframe'

Upvotes: 0

piedpiper
piedpiper

Reputation: 398

Complete answer that worked for me on JupyterLab 4.0.5

  • Install plotly pip install plotly
  • Install ipywidgets pip install ipywidgets
  • Specify the renderer as mentioned here and here
import plotly.express as px
import plotly.io as pio

# At least one of these should work
pio.renderers.default = 'iframe' # or 'notebook' or 'colab' or 'jupyterlab'

fig = px.scatter(df, x, y)

Then I could actually see the plot!

Upvotes: 0

J3ernhard
J3ernhard

Reputation: 252

As mentioned in the comment How to show Plotly figures in JupyterLab 3+? with JupyterLab 3.x and Plotly 5.x labextension installation of plotly is outdated.

Installation: https://plotly.com/python/getting-started/#installation

Upvotes: 0

Lucas
Lucas

Reputation: 258

To install Plotly on JupyterLab 3 on ubuntu is necessary to install nodejs, npm and jupyterlab plotly extension

The instructions on the plotly website didn't worked for me. The graph was being rendered as a white square. I discovered that jupyterlab plotly extension is working, but on Ubuntu it depends on nodejs and npm.

apt install nodejs npm
jupyter labextension install jupyterlab-plotly 

Reestart the jupyter and it should be working like the example bellow.

enter image description here

Upvotes: -1

Soerendip
Soerendip

Reputation: 9138

It is working now.

conda install -c plotly plotly=4.14.3
conda install "notebook>=5.3" "ipywidgets>=7.5"
jupyter labextension install [email protected]
# OPTIONAL: Jupyter widgets extension
jupyter labextension install @jupyter-widgets/jupyterlab-manager [email protected]

https://plotly.com/python/getting-started/

Upvotes: 2

Devin Burke
Devin Burke

Reputation: 538

This question has already been answered by one of the plotly developers.

Plotly express is not rendered in jupyter lab

Edit: That link is old sorry. After some more research it appears jupyter lab 3 is not currently compatible with plotly. They are currently working on it.

https://community.plotly.com/t/jupyterlab-plotly-not-compatible-with-jupyterlab-3-0/48777

Upvotes: 1

Related Questions