带有 Href 的散点图#
这个示例展示了一个散点图,使用了由汽车名称构建的 href 编码。通过这个编码,您可以点击任何一个点以打开关于汽车名称的谷歌搜索。
import altair as alt
from vega_datasets import data
source = data.cars()
alt.Chart(source).transform_calculate(
url='https://www.google.com/search?q=' + alt.datum.Name
).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
href='url:N',
tooltip=['Name:N', 'url:N']
)
import altair as alt
from vega_datasets import data
source = data.cars()
alt.Chart(source).transform_calculate(
url='https://www.google.com/search?q=' + alt.datum.Name
).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
href='url:N',
tooltip=['Name:N', 'url:N']
)
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.