plotly - 与谷歌 colab 合作,
问题描述
我正在 colab 上重新运行我的笔记本,而 plotly 的 fig.show 似乎不再起作用我尝试安装另一个 plotly 版本(我有 4.4.1),但我没有成功获得我的身材
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()
我什么都没看到。我需要将 HTML 与 HTML(fig.to_html()) 一起使用,但这不是解决方案,因为它在使用小部件后不起作用
你有什么主意吗 ?
我看到这篇文章Plotly notebook mode with google colaboratory但即使使用渲染器我也没有成功绘制任何东西
编辑:解决方案
- 定义
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)
- 然后在要绘制的任何单元格中调用此函数
#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()
解决方案
推荐阅读
- python - 如何根据另一个数据框中的变量从数据框中选择列
- python - 尝试在熊猫数据框中追加时获得“真”值而不是实际值
- cross-browser - browser.tabs.executescript() 在 Firefox 中不起作用
- python - ValueError: n_splits=3 不能大于每个类的成员数
- linux - tensorflow-1.12.0rc1-cp27-cp27mu-linux_x86_64.whl 不是这个平台支持的轮子
- dictionary - 在 Kotlin 中,如何以相反的顺序迭代 TreeMap?
- ios - 使用 CoreBluetooth 库停止信标扫描
- windows - 需要一种用于在软件中自动单击按钮的脚本语言
- sql - 具有不同返回值的函数 DB2
- python - 我使用centos中的以下代码读取python-pandas中的excel文件但我收到错误