带 Datum 着色的折线图#

使用 datumrepeat 为多系列折线图着色的示例。此示例改编自相应的 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"])