带有颜色数据的折线图#
使用 datum 和 repeat 给多系列折线图上色的示例。这是参考对应的Vega-Lite示例改编而来的:重复和层叠以展示不同的电影指标。
import altair as alt
from vega_datasets import data
source = data.movies()
alt.Chart(source).mark_line().encode(
alt.X("IMDB_Rating").bin(True),
alt.Y(alt.repeat("layer"))
.aggregate("mean")
.title("Mean of US and Worldwide Gross"),
color=alt.datum(alt.repeat("layer")),
).repeat(
layer=["US_Gross", "Worldwide_Gross"]
)
import altair as alt
from vega_datasets import data
source = data.movies()
alt.Chart(source).mark_line().encode(
x=alt.X("IMDB_Rating", bin=True),
y=alt.Y(
alt.repeat("layer"), aggregate="mean", title="Mean of US and Worldwide Gross"
),
color=alt.datum(alt.repeat("layer")),
).repeat(layer=["US_Gross", "Worldwide_Gross"])