简体   繁体   English

如何在 alt.color(condition=) 中使用 alt.condition()?

[英]How to use alt.condition() in alt.color(condition=)?

I'm new to altair so i want to be able to see my code more clearly.我是 altair 的新手,所以我希望能够更清楚地看到我的代码。 that's why i'm trying to use long version coding.这就是我尝试使用长版本编码的原因。 my problem is that, i could't find any documentation on how to use a alt.color(condition=) .我的问题是,我找不到任何关于如何使用alt.color(condition=)的文档。 How can i use condition= preferably with alt.condition() ?我如何最好将condition=alt.condition()一起使用?

brush = alt.selection_interval()

alt.Chart(cars).mark_point().encode(
    alt.Y("Horsepower"),
    alt.X("Miles_per_Gallon", title="consumption"),
    #alt.Tooltip(["Name", "Origin"]),
    #color=alt.condition(brush, 'Origin:N', alt.value('White')) I Know with this line my code will work 
    alt.Color(condition= alt.condition(brush,
                   alt.Color('Origin:N', legend=None),
                   alt.value('lightgray')))
).add_selection(
    brush
)

alt.condition is a shorthand for generating the full alt.Color specification for a conditional encoding. alt.condition是为条件编码生成完整的alt.Color规范的简写。 If you wish, you can create it more manually like this:如果您愿意,您可以像这样手动创建它:

    alt.Color(
        condition={"selection": brush.name, "field": "Origin", "type": "nominal"},
        value='lightgray')

If you're really set on using alt.condition as an argument to condition= , you could do something like this:如果您真的打算使用alt.condition作为condition=的参数,您可以执行以下操作:

    alt.Color(
        condition=alt.condition(brush, "Origin:N", "")["condition"],
        value='lightgray')

but it's a bit strange.但这有点奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM