Plotly 在 jupyter lab 中给出一个空字段作为输出
Plotly gives an empty field as output in jupyter lab
我在 jupyter 实验室使用 plotly,但我得到了空白输出。我遇到了与此处描述的完全相同的问题:
我尝试了他们在答案中的建议,但没有用。
这是我使用的代码:
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)
其中一个建议是将笔记本更改为 'trusted'。你知道我如何在 jupyter 实验室中做到这一点吗?
在 JupyterLab,
中正确显示 plotly
离线图表
第 1 步: 我们需要先为 JupyterLab 安装 plotly-extension
:
$ jupyter labextension install @jupyterlab/plotly-extension
(请注意,上述步骤需要 Node.js >= 4
,如果 Node.js 在您的 OS 上不可用,请从其 Official Website 安装它。)
第二步:安装后查看状态@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
第 3 步: 遵循建议,re-build JupyterLab 及其新安装的 labextensions:
$ jupyter lab build
在这些之后,重新启动 JupyterLab,并在每个笔记本会话开始时设置 plotly.offline.init_notebook_mode(connected=True)
,然后 plotly.offline.iplot
应该会在笔记本中正确显示绘图。
@YaOzI 的回答部分正确,但 @jupyterlab/plotly-extension
已被弃用并且不受官方 plotly 团队的支持,您可以阅读 here.
这会给您带来以下错误:
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
>>> TL;DR
:
按照官方建议,这对我有用(确保您的内核已关闭,否则您将需要 运行 jupyter lab build
):
jupyter labextension install jupyterlab-plotly
并且(只是为了确保它有效):
jupyter labextension list
可能会给你这样的东西:
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
version > 3.0
的 Jupyter 实验室安装扩展已更改。
查看 make plotly
在 Jupyter 实验室中的工作原理。检查official documentation
中需要安装的包
我在 jupyter 实验室使用 plotly,但我得到了空白输出。我遇到了与此处描述的完全相同的问题:
我尝试了他们在答案中的建议,但没有用。
这是我使用的代码:
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)
其中一个建议是将笔记本更改为 'trusted'。你知道我如何在 jupyter 实验室中做到这一点吗?
在 JupyterLab,
中正确显示plotly
离线图表
第 1 步: 我们需要先为 JupyterLab 安装 plotly-extension
:
$ jupyter labextension install @jupyterlab/plotly-extension
(请注意,上述步骤需要 Node.js >= 4
,如果 Node.js 在您的 OS 上不可用,请从其 Official Website 安装它。)
第二步:安装后查看状态@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
第 3 步: 遵循建议,re-build JupyterLab 及其新安装的 labextensions:
$ jupyter lab build
在这些之后,重新启动 JupyterLab,并在每个笔记本会话开始时设置 plotly.offline.init_notebook_mode(connected=True)
,然后 plotly.offline.iplot
应该会在笔记本中正确显示绘图。
@YaOzI 的回答部分正确,但 @jupyterlab/plotly-extension
已被弃用并且不受官方 plotly 团队的支持,您可以阅读 here.
这会给您带来以下错误:
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
>>> TL;DR
:
按照官方建议,这对我有用(确保您的内核已关闭,否则您将需要 运行 jupyter lab build
):
jupyter labextension install jupyterlab-plotly
并且(只是为了确保它有效):
jupyter labextension list
可能会给你这样的东西:
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
version > 3.0
的 Jupyter 实验室安装扩展已更改。
查看 make plotly
在 Jupyter 实验室中的工作原理。检查official documentation