pythonvisualizationlinechartaltairstacked-chart

How do I create a concatenated altair line chart like the example shown with the below dataframe?


I have the following dataframe:

Click here to see a picture of the dataframe

And I would like to create a concatenated Altair chart like the one below:

Concatenated Altair chart example

I have this so far but this is not working :

alt.Chart(prob_df).alt.Chart(prob_df).mark_line().encode(
    x='Key2',
    y='Year'
).properties(
width=150,
height=150
).facet(
facet='Key1',
columns=3
)

What would be the best way to create a graph for this


Solution

  • This should work:

    alt.Chart(prob_df).mark_line().encode(
        x='Year',
        y='Prob'
    ).properties(
        width=150,
        height=150
    ).facet(
        row='Key1',
        column='Key2'
    )