A compound chart combines multiple visualizations into one coordinated display. In Altair, it helps place complementary views together so a dataset can be compared, layered, or explored more informatively. section 3.2.4 section 3.4
Altair supports four main compound-chart patterns:
- Layering places charts on top of one another, using alt.layer(chart1, chart2) or the + operator. section 3.2.4
- Horizontal concatenation places charts side by side, using alt.hconcat() or the | operator. section 3.2.4
- Vertical concatenation stacks charts, using alt.vconcat() or the & operator. section 3.2.4
- Repeated charts generate similar views by varying data subsets or visual encodings with repeat(). section 3.2.4
Start with a shared chart
Create one base chart containing shared Country and Medals encodings, then derive a bar chart and a line chart with different marks. Layer them with alt.layer(chart1, chart2), or choose horizontal or vertical concatenation when separate views are clearer.
Repeat a chart across fields
Build a pandas DataFrame, remove the Country field from the repeated-field list, and use repeat(row=fields, column=fields) to create a grid of circle charts with changing quantitative encodings.
Listing 3.16 Building two charts in Altair
base = alt.Chart(df
).encode(
x='Country',
y='Medals'
).properties(
width=300
)
chart1 = base.mark_bar(
color='#636466'
).properties(
title='A bar chart'
)
chart2 = base.mark_line(
color='#80C11E'
).properties(
title='A line chart'
)
Inspect the shared-base pattern that progressively produces the bar and line charts used in compound-chart examples. section 3.2.4
