Jupyter notebook plotly not showing graph.. (just graph)

Viewed 10169

In jupyter notebook, My code do run.. just not showing graph.

I have tried many way..

My example code, picture.

My Code & picture

import plotly.offline as pyo
import plotly.graph_objs as go
pyo.init_notebook_mode()

trace0 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[5, 8, 2, 7]
)
trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[1, 5, 13, 2]
)
data = [trace0, trace1]
pyo.iplot(data, filename = 'ex')

enter image description here

And, I click a button; Download plot as png...

downloaded newplot.svg; open a file...

explorer

Capture newplot.svg

enter image description here

In new tap explorer, This graph show well.

why in jupyter notebook poltly not showing graph?

Just in case version. Add my python package version;

  • Python 3.7.4
  • plotly 4.5.2
  • numpy 1.16.6
  • seaborn 0.9.0
  • pandas 0.25.3
3 Answers

please refer to plotly's getting started documentation...

For use in the classic Jupyter Notebook, install the notebook and ipywidgets packages using pip...

$ pip install "notebook>=5.3" "ipywidgets>=7.2"

For use in JupyterLab, install the jupyterlab and ipywidgets packages using pip...

$ pip install jupyterlab "ipywidgets>=7.5"

Then run the following commands to install the required JupyterLab extensions (note that this will require node to be installed):

JupyterLab renderer support

jupyter labextension install jupyterlab-plotly@4.13.0

OPTIONAL: Jupyter widgets extension

jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.13.0

# Import the necessaries libraries
import plotly.offline as pyo
import plotly.graph_objs as go
# Set notebook mode to work in offline
pyo.init_notebook_mode()
# Create traces
trace0 = go.Bar(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = go.Bar(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
# Fill out data with our traces
data = [trace0, trace1]
# Plot it and save as basic-line.html
pyo.plot(data, filename = 'Test-bar.html', auto_open = False)

# Show HTML
from IPython.display import HTML
HTML(filename='Test-bar.html')

My method is Jupyter notebook Default program (Exploere -> Chrome)

Related