1

I am re running my notebooks on colab and the fig.show of plotly seems not work anymore I tried to install another plotly version (I have the 4.4.1) but I don't success to have my figure

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")
#fig.show()

I don't see anything. I need to use the HTML with HTML(fig.to_html()) but it is not a solution as it does not work after with widgets

Do you have any idea ?

I see this posts Plotly notebook mode with google colaboratory but I don't succeed to plot anything even with renderer

EDIT: Solution

  1. define
def enable_plotly_in_cell():
  import IPython
  from plotly.offline import init_notebook_mode
  display(IPython.core.display.HTML('''<script src="/static/components/requirejs/require.js"></script>'''))
  init_notebook_mode(connected=False)
  1. then call this function in any cell you want to plot
#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"
)
enable_plotly_in_cell()
fig.show()
parisjohn
  • 301
  • 2
  • 12

0 Answers0