I am trying to create a Sankey chart in a Jupyter notebook, basing my code on the first example shown here.
I ended up with this, which I can run without getting any
When using Google Colab, include the snippet -
import plotly.io as pio
pio.renderers.default = 'colab'
Or use the overall import statements as -
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.io as pio
pio.renderers.default = 'colab'
from plotly.offline import init_notebook_mode, iplot
This will set the rendering to Colab style and the plots will be displayed.
Hope this helps.
I have myself encountered a similar issue, with a sunburst plot. The blank plot was due to invalid data. I would have expected to get an error at runtime, but it appears that in some rare cases, no error is raised, and a blank plot is displayed instead.
Therefore, check your data validity, or perform a test with dummy data provided on plotly doc, in order to test if the problem comes from data or plotly/notebook interface.
I can get the correct display with jupyter notebook
server (without any additional options), but get a blank block
with jupyter lab
server. Related version info:
$ jupyter lab --version
0.35.5
$ jupyter notebook --version
5.7.8
$ python -c "import plotly; print(plotly.__version__)"
3.10.0
So for those who are using JupyterLab, to properly display the offline plotly
graphs in JupyterLab, we need to install the plotly-extension
with following commands (following is excerpted from a related answer):
$ jupyter labextension install @jupyterlab/plotly-extension
$ jupyter labextension list
$ jupyter lab build
I tried all the solutions suggested here, but none of them worked for me. What solved the issue was adding:
import plotly.io as pio
pio.renderers.default='notebook'
and also using fig.show("notebook")
rather than simply fig.show(), as suggested here.
From the quickstart in the README
This displays a figure, while none of the other answers here worked for me:
import plotly.graph_objs as go
fig = go.FigureWidget()
# Display an empty figure
fig
This (in a new cell) modifies the above plot with a bar and line chart:
# Add a scatter chart
fig.add_scatter(y=[2, 1, 4, 3])
# Add a bar chart
fig.add_bar(y=[1, 4, 3, 2])
# Add a title
fig.layout.title = 'Hello FigureWidget'
If that doesn't work, make sure your install is good, e.g. pip install --user --upgrade plotly
if you installed with pip
If none of these answers worked for you. Try this one
just do this in conda prompt opened with administrator permission
pip install pip --upgrade
conda upgrade notebook or pip install notebook --upgrade
conda install -c conda-forge ipywidgets or pip install ipywidgets
You need to have the latest versions of jupyter notebook
and ipywidgets
.