Plotly 在 jupyter lab 中给出一个空字段作为输出 [英] Plotly gives an empty field as output in jupyter lab

查看:36
本文介绍了Plotly 在 jupyter lab 中给出一个空字段作为输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我正在使用的代码:

将 pandas 导入为 pd将 numpy 导入为 np%matplotlib 内联从 plotly.offline 导入 download_plotlyjs, init_notebook_mode, plot, iplotinit_notebook_mode(连接=真)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 实验室怎么做吗?

解决方案

为了在 JupyterLab 中正确显示 plotly 离线图,p>

第一步:我们需要先安装plotly-extension 用于 JupyterLab:

$ jupyter labextension install @jupyterlab/plotly-extension

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

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

$ jupyter labextension listJupyterLab v0.35.5已知的实验室扩展:应用程序目录:/Users/yourname/anaconda3/share/jupyter/lab@jupyterlab/plotly-extension v0.18.2 启用 OK推荐构建,请运行`jupyter lab build`:@jupyterlab/plotly-extension 需要包含在构建中

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

$ jupyter lab build

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

I'm using plotly at jupyter lab, but I'm getting a blanked output. I'm having exactly the same problem described here: plotly.offline.iplot gives a large blank field as its output - why?

And I tried what they suggested in the answers, but it didn't work.

Here is the code I'm using:

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)

One of the suggestions was to change the notebook to 'trusted'. Do you know how can I do it in jupyter lab?

解决方案

To properly display the plotly offline graphs in JupyterLab,

Step 1: We need to first install the plotly-extension for JupyterLab:

$ jupyter labextension install @jupyterlab/plotly-extension

(Note that the above step requires Node.js >= 4, if Node.js is not available on your OS, install it from its Official Website.)

Step 2: Check the status after the installation of @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

Step 3: Follow the suggestion, re-build the JupyterLab with its newly installed labextensions:

$ jupyter lab build

After these, restart JupyterLab, and set plotly.offline.init_notebook_mode(connected=True) at the start of each notebook session, then plotly.offline.iplot should correctly display the plots in the notebook.

这篇关于Plotly 在 jupyter lab 中给出一个空字段作为输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆