I'm new to altair so i want to be able to see my code more clearly. 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=)
. How can i use condition=
preferably with 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. 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.Color(
condition=alt.condition(brush, "Origin:N", "")["condition"],
value='lightgray')
but it's a bit strange.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.