我正在尝试创建一个简单的条形图(特定字段有多个列):
bars = alt.Chart(df_probing).mark_bar(stroke='transparent').encode(
alt.X('model_name:N', scale=alt.Scale(rangeStep=12), axis=alt.Axis(title='')),
alt.Y('acc:Q', axis=alt.Axis(title='Accuracy', grid=False)),
color=alt.Color('model_name:N'),
column='task_name:N'
).configure_view(
stroke='transparent'
).configure_axis(
domainWidth=0.8
)
现在,这个图运行良好,但是当我尝试在条形顶部添加值标签时,如下所示:
text = bars.mark_text(
align='center',
).encode(
text='acc:Q'
)
bars + text
它抛出以下错误:
ValueError: Objects with "config" attribute cannot be used within LayerChart. Consider defining the config attribute in the LayerChart object instead.
如何将条形标签添加到刻面/分层图上条形图中的每个条形?