Objective
I want to generate a ‘double ended’ barchart, showing gained points (of some metric) vis-a-vis missed points, something like this:
Result so far
I managed to do this
import altair as alt
import pandas as pd
source = pd.DataFrame(
{
"cohort": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
"gained": [28, 55, 43, 91, 81, 53, 19, 87, 52],
"missed": [5, 8, 34, 21, 16, 22, 9, 7, 11],
}
)
up = (
alt.Chart(source)
.mark_bar(color="blue")
.encode(
x=alt.X("cohort:N").axis(labels=False, title=None, ticks=False),
y=alt.Y("gained:Q"),
)
)
down = (
alt.Chart(source)
.mark_bar(color="red")
.encode(
x=alt.X("cohort:N").axis(labelAngle=0),
y=alt.Y("missed:Q", scale=alt.Scale(reverse=True)),
)
)
alt.vconcat(up, down).resolve_scale(x="shared")
which generates this:
Is there any way I can remove the gap? Or perhaps go about it completely differently with Vega-Altair?