尽管已安装扩展,但在Jupyterlab中未显示绘图图

时间:2020-06-26 18:58:18

标签: plotly

我有一个奇怪的问题。 Jupyterlab不会显示绘图,但在Jupyter笔记本中,一切正常。 我到处搜索,许多人说应该安装plotly-extension。我已经安装了plotly扩展。我正在处理的笔记本是值得信任的。我不知道该怎么办。

import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(y=[2, 1, 4, 3]))
fig.add_trace(go.Bar(y=[1, 4, 3, 2]))
fig.update_layout(title = 'Hello Figure')
fig.show()

This is what jupyterlab shows me

2 个答案:

答案 0 :(得分:0)

刚刚遇到了同样的问题,因为我使用的是 Anaconda,所以在“服务器”环境中,除了安装 Plotly 之外,我还安装了以下 JupyterLab 扩展:

  • jupyterlab-plotly

    jupyter labextension install jupyterlab-plotly@4.14.1
    
  • plotlywidget [可选]

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

为了安装扩展,nodejs 是必需的。

更详细的答案check my answer here

答案 1 :(得分:-1)

考虑在笔记本中添加以下代码行:

from plotly.offline import init_notebook_mode
init_notebook_mode(connected=True)
plotly.offline.init_notebook_mode(connected=True)