Plotly 在 jupyter 实验室中给出一个空字段作为输出

Led*_*ele 18 python plotly jupyter jupyter-notebook jupyter-lab

我在 jupyter 实验室使用 plotly,但我得到一个空白的输出。我在这里描述了完全相同的问题:plotly.offline.iplot 给出了一个大的空白字段作为其输出 - 为什么?

我尝试了他们在答案中的建议,但没有奏效。

这是我正在使用的代码:

import pandas as pd
import numpy as np
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
cf.go_offline()

df = pd.DataFrame(np.random.randn(100,4), columns='A B C D'.split())
df2 = pd.DataFrame({'category':['A','B','C'], 'values':[32,43,50]})

df.iplot(kind='scatter', x='A',y='B', mode='markers', size=10)
Run Code Online (Sandbox Code Playgroud)

建议之一是将笔记本更改为“受信任”。你知道我如何在 jupyter 实验室中做到这一点吗?

YaO*_*OzI 12

plotlyJupyterLab 中正确显示离线图形,

第 1 步:我们需要先安装plotly-extensionJupyterLab:

$ jupyter labextension install @jupyterlab/plotly-extension
Run Code Online (Sandbox Code Playgroud)

(请注意,上述步骤需要Node.js >= 4,如果您的操作系统上没有 Node.js,请从其官方网站安装它。)

第 2 步:检查安装后的状态@jupyterlab/plotly-extension

$ jupyter labextension list 
JupyterLab v0.35.5
Known labextensions:
   app dir: /Users/yourname/anaconda3/share/jupyter/lab
        @jupyterlab/plotly-extension v0.18.2  enabled  OK

Build recommended, please run `jupyter lab build`:
    @jupyterlab/plotly-extension needs to be included in build
Run Code Online (Sandbox Code Playgroud)

第 3 步:按照建议,使用新安装的 labextensions 重新构建 JupyterLab:

$ jupyter lab build
Run Code Online (Sandbox Code Playgroud)

在这些之后,重新启动 JupyterLab,并plotly.offline.init_notebook_mode(connected=True)在每个 notebook 会话开始时进行设置,然后plotly.offline.iplot应该正确地显示 notebook 中的绘图。

  • 该软件包(@jupyterlab/plotly-extension)已被弃用。请使用 Plotly 支持的 jupyterlab-plotly (https://www.npmjs.com/package/jupyterlab-plotly)。 (2认同)

小智 8

@YaOzI 答案部分正确,但@jupyterlab/plotly-extension已弃用,官方情节团队不支持,您可以在此处阅读

这可能会给您以下错误:

ValueError: The extension "@jupyterlab/plotly-extension" does not yet support the current version of JupyterLab.


Conflicting Dependencies:
JupyterLab                        Extension      Package
>=2.2.1 <2.3.0                    >=1.3.0 <2.0.0 @jupyterlab/rendermime-interfaces
See the log file for details:  /tmp/jupyterlab-debug-a3i3t9j4.log
Run Code Online (Sandbox Code Playgroud)

>>> TL;DR

按照官方建议,这对我有用(确保您的内核已关闭,否则您将需要运行jupyter lab build):

jupyter labextension install jupyterlab-plotly
Run Code Online (Sandbox Code Playgroud)

并且(只是为了确保它有效):

jupyter labextension list
Run Code Online (Sandbox Code Playgroud)

可能会给你这样的东西:

JupyterLab v2.2.9
Known labextensions:
   app dir: /home/user/anaconda3/envs/your-py-env/share/jupyter/lab
        jupyterlab-dash v0.3.0  enabled  OK
        jupyterlab-plotly v4.14.1  enabled  OK

Run Code Online (Sandbox Code Playgroud)