liveBook · Manning

Compound chart

As explained in Data Storytelling with Altair and AI

A compound chart is a visualization composed of multiple charts combined into a coordinated graphical display.

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

How Data Storytelling with Altair and AI covers it

How deep it goes
Explains four composition patterns with APIs and operators, but stops short of deeper Vega-Lite specification details.
Examples
Uses shared bar-and-line charts, layered and concatenated layouts, and a repeated quantitative-encoding grid.
What it assumes
Assumes basic Altair charts, marks, encodings, and pandas DataFrames; reinforces composition through progressively defined examples.
What you can do after
Build it from scratch with Altair by layering, concatenating, or repeating separately defined charts.
How it connects
Connects compound charts to Altair, Vega-Lite, encodings, marks, interactivity, configurations, layering, concatenation, and repeated charts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.