import pandas as pd
import numpy as np
import altair as alt
key_x = "Whatever X Is"
key_col = "Color Parameter"
key_y = "Performance or Error"
np.random.seed(0)
charts = []
for sweep, title in zip([
[0.0, 0.1, 0.5, 0.95],
[0.0, 0.1, 0.5, 0.75, 1.0, 10.0],
[0.01, 0.05, 0.1],
], [
"Parameter 1",
"Parameter 2",
"Parameter 3",
]):
x = []
y = []
col = []
for col_val in range(3):
for x_val in sweep:
for seed in range(100):
col += [col_val]
x += [x_val]
y += [np.random.normal(col_val, x_val)]
df = pd.DataFrame({
f"{key_x}": x,
f"{key_y}": y,
f"{key_col}": col,
})
bars = alt.Chart(df, width=600, height=100).mark_bar(tooltip=True).encode(
x=alt.X(
f"{key_x}:N",
axis=alt.Axis(labelAngle=0, title=title),
),
y=alt.Y(f"mean({key_y}):Q"),
color=alt.Color(f"{key_col}:N"),
xOffset=alt.XOffset(f"{key_col}:N"),
)
charts.append(bars)
chart = alt.vconcat(*charts)
chart.save("altair_concat.html")
The three charts in concatenate have different number of x values but it seems that the first one dictates the width and the bar width of the next ones. How can I make them independent?