Altair在binding_radio中更改标签的颜色

时间:2020-07-10 23:29:10

标签: python altair

我想在binding_radio选择器中更改“此标签”的颜色:可以吗?

我什么都找不到...

任何帮助将不胜感激!

df = pd.DataFrame({'x':[0,0],'y':[10,20],'color':['red','blue']})

groups = df['y'].tolist()
radio_groups = alt.binding_radio(
    options = groups, 
    name    = 'This label'
)
select_group = alt.selection(
    type   = 'single', 
    fields = ['y'],
    bind   = radio_groups, 
    empty  ='none',
    init   = {'y': 10}
)

alt.Chart(
    df
).mark_bar(
).encode(
    x = 'x:O',
    y='y:O',
    color = 'y:O'
).add_selection(
    select_group
).transform_filter(
    select_group
)

1 个答案:

答案 0 :(得分:2)

绑定样式不能通过图表规范来控制,但是可以通过标准CSS规范来控制。您可以使用浏览器检查工具来确定所涉及的标签是类别为span的{​​{1}}元素。

如果您使用的是Jupyter笔记本,则注入CSS的方法如下:

vega-bind-name

将其添加到单元格后,结果图表如下所示: enter image description here