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

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

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

问题描述

我在jupyter实验室使用了plotly,但输出却空白.我在这里描述的问题完全相同:

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)

其中一项建议是将笔记本更改为可信任".您知道我如何在Jupyter实验室中做到这一点吗?

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

推荐答案

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

To properly display the plotly offline graphs in JupyterLab,

步骤1:我们需要首先安装 plotly-extension 对于JupyterLab:

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

$ jupyter labextension install @jupyterlab/plotly-extension

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

(Note that the above step requires Node.js >= 4, if Node.js is not available on your OS, install it from its 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:

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

$ jupyter lab build

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

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.

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

07-29 18:21