繁体   English   中英

Plotly 在 jupyter lab 中给出一个空字段作为输出

[英]Plotly gives an empty field as output in 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)

建议之一是将笔记本更改为“受信任”。 你知道我在jupyter实验室怎么做吗?

要在plotly中正确显示绘图离线图,

第 1 步:我们需要首先为 JupyterLab 安装plotly-extension

$ jupyter labextension install @jupyterlab/plotly-extension

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

第二步:检查@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应该正确显示笔记本中的绘图。

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

这可能会给您以下错误:

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

为 Jupyter 实验室安装扩展已更改为version > 3.0

看看 make plotly在 Jupyter 实验室中是如何工作的。 官方文档中查看需要安装的包

我有同样的问题,但解决方案对我来说有点不同。

我正在使用 jupyterhub 并且我的虚拟环境是 jupyter 内核,因此使用上述步骤没有帮助。

我不得不:

  1. 登录到我的 jupyterhub docker 容器docker exec -it jupyterhub bash
  2. 确保安装了正确的软件包pip install "jupyterlab>=3" "ipywidgets>=7.6"
  3. 安装 plotly 扩展jupyter labextension install jupyterlab-plotly
  4. 构建 jupyter jupyter lab build

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM