【问题标题】:Validation fails when using plotly in jupyter notebook在 jupyter notebook 中使用 plotly 时验证失败
【发布时间】:2018-04-05 05:46:48
【问题描述】:

当我保存带有绘图图的 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': {}}

我在笔记本上的代码是:

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)

plotly plots in jupyter notebooks: Validation fails when saving 之后,我更新了 nbformat,但仍然无法正常工作(我检查了 import nbformat nbformat__version__ 更新工作)

【问题讨论】:

  • 我遇到了同样的问题。将这些示例中的任何一个复制并粘贴到 jupyter 笔记本中(并将最后一行更改为离线绘图)会重现验证错误。 plot.ly/python/choropleth-maps

标签: python jupyter-notebook plotly


【解决方案1】:

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

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

【讨论】:

  • 这个“hack”对我也有用,谢谢!你知道这个nbformat_minor 做什么吗?它是否与使用的 nbformat 版本有关,也可以通过 conda 或 pip 安装正确的版本设置为“globaly”?
  • @Hellvetia,不幸的是,我不知道。也许它将保存模式切换为“离线”或类似的东西。如果你发现了,请告诉我们!
【解决方案2】:

我遇到了另一个错误 -

Notebook validation failed: {'type': 'string'} is not valid under any of the given schemas: { "type": "string" }

但是将 "nbformat_minor": 1 替换为 "nbformat_minor": 4 对我有用。

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多