Trellis Bar Chart

< Anscombe’s Quartet | Example Gallery | Trellis Histograms >

from altair import *

Chart('https://vega.github.io/vega-lite/data/population.json',
    description='A trellis bar chart showing the US population distribution of age groups and gender in 2000.',
).mark_bar().encode(
    color=Color('gender:N',
        scale=Scale(
            range=['#EA98D2', '#659CCA'],
        ),
    ),
    row='gender:N',
    x=X('age:O',
        scale=Scale(
            bandSize=17.0,
        ),
    ),
    y=Y('sum(people):Q',
        axis=Axis(
            title='population',
        ),
    ),
).transform_data(
    calculate=[Formula(
            expr='datum.sex == 2 ? "Female" : "Male"',
            field='gender',
        )],
    filter='datum.year == 2000',
)