如果您在重复图表中得到空图,通常意味着以下两种情况之一:
- 前端无法访问您的数据。例如,如果您将数据作为 URL 传递并且 URL 有拼写错误,则可能会发生这种情况。
- 行/列中使用的列名输入错误。
作为第二个问题的示例,请考虑Altair 文档中的此图表:
import altair as alt
from vega_datasets import data
iris = data.iris.url
alt.Chart(iris).mark_point().encode(
alt.X(alt.repeat("column"), type='quantitative'),
alt.Y(alt.repeat("row"), type='quantitative'),
color='species:N'
).properties(
width=200,
height=200
).repeat(
row=['petalLength', 'petalWidth'],
column=['sepalLength', 'sepalwidth']
).interactive()

现在让我们看看如果我们拼错列名会发生什么(这里我们的“拼写错误”涉及将大写字符更改为小写):
alt.Chart(iris).mark_point().encode(
alt.X(alt.repeat("column"), type='quantitative'),
alt.Y(alt.repeat("row"), type='quantitative'),
color='species:N'
).properties(
width=200,
height=200
).repeat(
row=['petallength', 'petalwidth'],
column=['sepallength', 'sepalwidth']
).interactive()

确保您没有拼错列名:常见问题是大写与小写、特殊字符以及列名字符串开头或结尾处的空格。