Skip to content Skip to sidebar Skip to footer

How To Display Plotly Outputs In Google Collaboratory Notebooks?

I searched whole day how to display the outputs of plotly plots in google colaboratory jupyter notebooks. There is a stackoverflow question and also official tutorial from google c

Solution 1:

plotly version 4.x

As of version 4, plotly renderers know about Colab, so the following is sufficient to display a figure in both Colab and Jupyter (and other notebooks like Kaggle, Azure, nteract):

import plotly.graph_objects as go
fig = go.Figure( go.Scatter(x=[1,2,3], y=[1,3,2] ) )
fig.show()

plotly version 3.x

I was also struggling to display the plotly graphs in Google colab and stumbled upon this thread where you explained the problems with different solutions over the net. Feelings are the same for each one of the solutions. Finally, my search ended when I came across this video.

I followed his approach (might be similar to the ones you already tried) and this worked for me.

  1. Upgrade plotly in colab thru !pip install plotly --upgrade and restart runtime as suggested.
  2. Comment the upgrade option before re-running your notebook
  3. Define the function configure_plotly_browser_state()
  4. Invoke plotly libraries
  5. Call function and notebook mode like below in every cell where you want to call iplot

    configure_plotly_browser_state()

    init_notebook_mode(connected=False)

    iplot(XXXXXX)

Just import plotly libraries

Please let me know if this helps :)

Solution 2:

Add line '%matplotlib inline' at the beginning of notebooks

Refer below link: https://github.com/jupyter/notebook/issues/3523

Solution 3:

Try to use renderer="colab" as shown below:

import plotly.graph_objects as go
fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with the 'colab' Renderer"
)
fig.show(renderer="colab")

Solution 4:

Use plot and not iplot ...it took me a while for this one to figure out. You can the plot both to the notebook and to gdrive.

Post a Comment for "How To Display Plotly Outputs In Google Collaboratory Notebooks?"