【问题标题】:Altair - plotting custom colorsAltair - 绘制自定义颜色
【发布时间】:2020-06-16 01:59:19
【问题描述】:

我想用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.
        )

但这不起作用。它绘制蓝色。有可能吗?

【问题讨论】:

    标签: python altair


    【解决方案1】:

    是的,您可以使用值编码来做到这一点:

    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.
    )
    

    【讨论】:

    • 谢谢。但它只适用于color=alt.value(f'{color})。必须删除:N
    猜你喜欢
    • 2016-12-17
    • 2022-01-20
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多