无论如何,在 Altair 中,是否可以弹出地图的一部分或更改选择的颜色

Dee*_*pak 3 python altair

我正在尝试在 Altair 中绘制印度的各州。我能够绘制并在工具提示中显示州名称。我希望该州在选择时弹出或更改颜色。有什么办法可以做到这一点。

我尝试使用选择间隔。但无法做到这一点,因为我是新手

'''Python

import altair as alt

url = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/india/india-states.json"

source = alt.topo_feature(url, "IND_adm1")

alt.Chart(source).mark_geoshape().encode(
    tooltip='properties.NAME_1:N',
    color=alt.value('lightgray')   

).properties(
        width=800,
        height=500

)
Run Code Online (Sandbox Code Playgroud)

jak*_*vdp 5

您可以使用带有条件颜色的单选来执行如下操作:

import altair as alt

url = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/india/india-states.json"

source = alt.topo_feature(url, "IND_adm1")
hover = alt.selection_single(on='mouseover', empty='none')

alt.Chart(source).mark_geoshape().encode(
    tooltip='properties.NAME_1:N',
    color=alt.condition(hover, alt.value('steelblue'), alt.value('lightgray'))
).properties(
    width=800,
    height=500
).add_selection(
    hover
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述