我有一些想用altair
绘制的自定义颜色。
说color = '#CE1317'
:
bar = alt.Chart(df).mark_bar().encode(
alt.X('Performance Indicator:N', title=""),
alt.Y(f'{player[0]}:Q', title="", sort='-x', scale=alt.Scale(domain=(0.0, 2.5))),
color=f'{color}:N',
tooltip=[f'{player[0]}:Q']
).properties(
height=600,
width=alt.Step(40) # controls width of bar.
)
但这不起作用。它绘制蓝色。有可能吗?
答案 0 :(得分:2)
是的,您可以使用值编码来做到这一点:
bar = alt.Chart(df).mark_bar().encode(
alt.X('Performance Indicator:N', title=""),
alt.Y(f'{player[0]}:Q', title="", sort='-x', scale=alt.Scale(domain=(0.0, 2.5))),
color=alt.value(color),
tooltip=[f'{player[0]}:Q']
).properties(
height=600,
width=alt.Step(40) # controls width of bar.
)