我在jupyter实验室使用了plotly,但输出却空白。我遇到的问题完全相同:plotly.offline.iplot gives a large blank field as its output - why?
我尝试了他们在答案中提出的建议,但是没有用。
这是我正在使用的代码:
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)
其中一项建议是将笔记本更改为“可信任”。你知道我怎么在jupyter实验室做吗?
答案 0 :(得分:3)
@YaOzI的回答部分正确,但是@jupyterlab/plotly-extension
已过时,官方的绘图团队不支持,因为您可以阅读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
答案 1 :(得分:2)
要在 JupyterLab 中正确显示 plotly
离线图形,
步骤1:我们需要首先为JupyterLab安装plotly-extension
:
$ jupyter labextension install @jupyterlab/plotly-extension
(请注意,上述步骤需要Node.js >= 4
,如果您的操作系统上没有Node.js,请从其Official Website安装。)
步骤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
步骤3:按照建议,使用新安装的labextensions重新构建JupyterLab:
$ jupyter lab build
之后,重新启动JupyterLab,并在每个笔记本会话开始时设置plotly.offline.init_notebook_mode(connected=True)
,然后plotly.offline.iplot
应该在笔记本中正确显示绘图。