gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:01 24 4
gpt4 key购买 nike

我在 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 实验室中做到这一点吗?

最佳答案

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

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

$ jupyter labextension install @jupyterlab/plotly-extension

(请注意,上述步骤需要 Node.js >= 4,如果 Node.js 在您的操作系统上不可用,请从其 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 步:按照建议,使用新安装的 labextensions 重新构建 JupyterLab:

$ jupyter lab build

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

关于python - Plotly 在 jupyter lab 中给出一个空字段作为输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54936125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com