【问题标题】:Altair mark_image not working due to Javascript error由于 Javascript 错误,Altair mark_image 无法正常工作
【发布时间】:2021-04-23 23:29:06
【问题描述】:

我正在运行以下代码(完全复制自官方文档 here)来创建带有图像标记的散点图。

import altair as alt
import pandas as pd

source = pd.DataFrame.from_records([
      {"x": 0.5, "y": 0.5, "img": "https://vega.github.io/vega-datasets/data/ffox.png"},
      {"x": 1.5, "y": 1.5, "img": "https://vega.github.io/vega-datasets/data/gimp.png"},
      {"x": 2.5, "y": 2.5, "img": "https://vega.github.io/vega-datasets/data/7zip.png"}
])

alt.Chart(source).mark_image(
    width=50,
    height=50
).encode(
    x='x',
    y='y',
    url='img'
)

它正在返回此错误消息:

Javascript 错误:未定义不是对象(评估 'n[e.type][t]')

这通常意味着您的图表规范中有错字。请参阅 JavaScript 控制台以获取完整的回溯。

该错误消息是什么意思?我是否缺少一些显示图像所需的库?

【问题讨论】:

  • 您能否提供有关您如何运行代码的信息? Jupyter实验室?如果是这样,哪个浏览器?如果您有插件干扰 JS,您可能想在私人/隐身窗口中尝试。哪个版本的 Altair?
  • 我尝试在jupyterlab环境下运行。正常显示。使用的版本是:altair:4.1.0。下面列出了相关模块,它们是最新的吗? jinja2, jsonschema, entrypoints, numpy, pandas, toolz

标签: python altair


【解决方案1】:

嗯...我没有做任何更改,并且当我今天运行相同的代码时它可以工作。

感谢@joelostblom 和@r-beginners 的建议。我在 Safari 浏览器的 Jupyter 笔记本中运行代码。以下是我的相关模块的版本:

  • altair 4.1.0
  • jinja2 2.11.2
  • jsonschema 3.2.0
  • 入口点 0.3
  • numpy 1.19.5
  • 熊猫 1.1.5
  • 工具 0.11.1
  • jupyter-notebook 6.1.4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 2020-02-25
    相关资源
    最近更新 更多