带工具提示的简单散点图#
cars 数据集的散点图,当您将鼠标悬停在点上时,会显示所选列值的工具提示。我们将点放大,以便更容易悬停在其上。
import altair as alt
from vega_datasets import data
source = data.cars()
alt.Chart(source).mark_circle(size=60).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()
import altair as alt
from vega_datasets import data
source = data.cars()
alt.Chart(source).mark_circle(size=60).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.