我制作了这张图表:

使用此代码:
q2 = alt.Chart(source, width=100, height=100).mark_line().encode(
y=alt.Y("prob:Q", title = ''),
x=alt.X("year:O", title = ''),
row=alt.Row("key1:N", title="Probability of "),
column=alt.Column("key2:N", title="Given..."),
)但是我需要“给予.”“概率”出现在每一行上,而不仅仅是一次,而且年数显示在每个图的x轴上。下面是它应该是什么样子:

下面是我的工作数据:

我知道这需要一些级别的连接,但我不知道如何将这一概念应用到我的图表中。我试过这样做:
charts = []
for key in totest:
data = source[source['key1'] == key]
chart = alt.Chart(data).mark_line().encode(
y=alt.Y("prob:Q", title = ''),
x=alt.X("year:O", title = ''),
row=alt.Row("key1:N", axis=alt.Axis(title=['Probability of', key])),
facet = alt.Facet("key2:N", sort=totest, title = "Given...")
)
charts.append(chart)
return alt.vconcat(*charts)但我知道这个错误:
SchemaValidationError: Invalid specification
altair.vegalite.v4.schema.channels.Row, validating 'additionalProperties'
Additional properties are not allowed ('axis' was unexpected)
alt.VConcatChart(...)发布于 2021-11-29 00:48:45
错误并不特别清楚,但问题是Vega渲染器不支持分面图表的级联。除了显示多个图表而不是将它们连在一起之外,我不知道有什么好的解决办法来做您想做的事情:
for key in totest:
data = source[source['key1'] == key]
chart = alt.Chart(data).mark_line().encode(
y=alt.Y("prob:Q", title = ''),
x=alt.X("year:O", title = ''),
row=alt.Row("key1:N", axis=alt.Axis(title=['Probability of', key])),
facet = alt.Facet("key2:N", sort=totest, title = "Given...")
)
chart.display()https://stackoverflow.com/questions/70146671
复制相似问题