Altair 在 binding_radio 中更改标签的颜色
Altair change color of label in binding_radio
我想更改 binding_radio 选择器中 'This label' 的颜色:可以吗?
我找不到任何相关信息...
如有任何帮助,我们将不胜感激!
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
)
绑定的样式无法通过图表规范控制,但可以通过标准 CSS 规范控制。您可以使用浏览器检查工具来确定有问题的标签是一个带有 class vega-bind-name
.
的 span
元素
如果您在 Jupyter notebooks 中工作,注入 CSS 的一种方法如下所示:
from IPython.display import display, HTML
display(HTML("""
<style>
span.vega-bind-name {
color: red;
}
</style>
"""))
将此添加到单元格后,生成的图表如下所示:
我想更改 binding_radio 选择器中 'This label' 的颜色:可以吗?
我找不到任何相关信息...
如有任何帮助,我们将不胜感激!
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
)
绑定的样式无法通过图表规范控制,但可以通过标准 CSS 规范控制。您可以使用浏览器检查工具来确定有问题的标签是一个带有 class vega-bind-name
.
span
元素
如果您在 Jupyter notebooks 中工作,注入 CSS 的一种方法如下所示:
from IPython.display import display, HTML
display(HTML("""
<style>
span.vega-bind-name {
color: red;
}
</style>
"""))
将此添加到单元格后,生成的图表如下所示: