'How can I make one chart "span" the height / width of multiple charts in concatenated plots?

In the following example, I'd like to have exp fill the entire width of the plot (so, as wide as sin and cos combined). By default, exp fills only one column.

How can I do this, ideally using some "auto" setting (without explicitly setting a width= to a number)?

import altair as alt
import numpy as np
import pandas as pd

x = np.linspace(0, 20, 100)
source = pd.DataFrame({
  'x': x,
  'sin': np.sin(x),
  'cos': np.cos(x),
  'exp': np.exp(x),
})

base = alt.Chart(source).mark_line().encode(x='x')
sin = base.encode(y='sin')
cos = base.encode(y='cos')
exp = base.encode(y='exp')
(sin | cos) & exp

enter image description here



Solution 1:[1]

A similar solution for width:

w = 200
spacing = 64

base = alt.Chart(source).mark_line().encode(x='x')
sin = base.encode(y='sin').properties(width=w, height=100)
cos = base.encode(y='cos').properties(width=w, height=100)
exp = base.encode(y='exp').properties(width=2*w+spacing, height=100)

row = alt.hconcat(sin, cos).properties(
    bounds='flush',
    spacing=spacing
)
                  
alt.vconcat(row, exp).configure_axisY(labelLimit=spacing)

chart

Not aligned, but maybe visually nice enough with less code:

w = 200

base = alt.Chart(source).mark_line().encode(x='x')
sin = base.encode(y='sin').properties(width=w, height=100)
cos = base.encode(y='cos').properties(width=w, height=100)
exp = base.encode(y='exp').properties(width=2*w, height=100)

row = alt.hconcat(sin, cos)
alt.vconcat(row, exp).properties(center=True)

chart2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 debbes