【发布时间】:2019-07-22 14:31:22
【问题描述】:
当尝试向包含行的 Altair 条形图添加标签时,我收到 SchemaValidationError。我说的是这样的标签: https://altair-viz.github.io/gallery/bar_chart_with_labels.html
我说的是带有行的条形图或“水平分组条形图”,如下所示: https://altair-viz.github.io/gallery/grouped_bar_chart_horizontal.html
这是不起作用的代码:
from vega_datasets import data
source = data.barley()
bars = alt.Chart(source).mark_bar().encode(
x='sum(yield):Q',
y='year:O',
row='variety:N',
)
bars
text = bars.mark_text(
align='left',
baseline='middle',
dx=3 # Nudges text to right so it doesn't appear on top of the bar
).encode(
text='sum(yield):Q'
)
bars + text
如果我删除条形图中的行选项,它会按预期工作:
bars = alt.Chart(source).mark_bar().encode(
x='sum(yield):Q',
y='year:O'
)
bars
text = bars.mark_text(
align='left',
baseline='middle',
dx=3 # Nudges text to right so it doesn't appear on top of the bar
).encode(
text='sum(yield):Q'
)
bars + text
将行添加到 'mark_text' 方法也无济于事...
最后,我希望看到条形右侧的标签,如下所示: https://imgur.com/KFJtNkb
【问题讨论】:
标签: python python-3.x jupyter-notebook altair