'Does anyone know how to use plotly express offline?

I am trying to run an example code to visualise a plotly chart, as below:

import plotly.express as px
from plotly.offline import init_notebook_mode, iplot, plot
import plotly.offline as py  
py.init_notebook_mode(connected=True)

%matplotlib inline
df = pd.DataFrame([
    ['Europe', 586098529, 'Total'], ['Asia', 3811953827, 'Total'],
    ['France', 61083916, 'Europe'], ['Germany', 82400996, 'Europe'], ['Italy', 58147733, 'Europe'],
    ['Spain', 40448191, 'Europe'], ['United Kingdom', 60776238, 'Europe'], ['Taiwan', 23174294, 'Asia'],
    ['Japan', 127467972, 'Asia'], ['Korean', 49044790, 'Asia'], ['China', 1318683096, 'Asia']],
    columns=['country', 'pop', 'continent'])
fig = px.sunburst(df, names='country', values='pop', parents='continent', title='Population')

plot(fig,show_link = False)

When I run this, a new internet browser opens up to show the chart. Is there a way to show this just in Jupyter itself?



Solution 1:[1]

  1. as @r-beginners mentioned, fig.show() displays a graph in Jupyter
  2. check if you've installed ipywidgets>=7.5 for Jupyter Notebook or jupyterlab-plotly and plotlywidget for Jupyter Lab
  3. check out this StackOverflow discussion
  4. getting started guide by plotly
  5. troubleshooting guide

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konstantin Z