在 jupyter notebook 中使用 plotly 时验证失败

A.V*_*non 5 python plotly jupyter-notebook

当我用绘图保存 jupyter 笔记本时,出现以下错误:

[E 13:42:38.458 NotebookApp] Notebook JSON is invalid: {'data': [{'type': 'scatter', 'y': [1, 2, 3]}], 'layout': {}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['data']['patternProperties']['^(?!application/json$)[a-zA-Z0-9]+/[a-zA-Z0-9\\-\\+\\.]+$']:
    {'oneOf': [{'type': 'string'},
               {'items': {'type': 'string'}, 'type': 'array'}]}

On instance['data']['application/vnd.plotly.v1+json']:
    {'data': [{'type': 'scatter', 'y': [1, 2, 3]}], 'layout': {}}
Run Code Online (Sandbox Code Playgroud)

我在笔记本中的代码是:

import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode(connected=True)
data = [go.Scatter(y=[1,2,3])]
py.iplot(data)
Run Code Online (Sandbox Code Playgroud)

遵循jupyter 笔记本中的情节图:保存时验证失败,我更新了 nbformat 但仍然无法正常工作(我检查import nbformat nbformat__version__了更新是否有效)

Top*_*000 4

我遇到了同样的问题。我尝试更新 nbformat 甚至conda update --all但这也没有帮助。

后来我得到了一个链接: https: //gitmemory.com/issue/jupyter/nbformat/161/574959380。因此,我使用文本编辑器打开 ipynb 文件,将“nbformat_minor”:1替换为“nbformat_minor”:4并保存文件。重新加载笔记本后问题得到解决。