水平堆叠条形图#

这是水平堆叠条形图的一个示例,使用了包含 20 世纪 30 年代不同区域和不同年份作物产量的数据。

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x='sum(yield)',
    y='variety',
    color='site'
)
import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x='sum(yield)',
    y='variety',
    color='site'
)
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.