Wednesday 4 August 2021

stacked chart combine with alluvial plot - python

Surprisingly little info out there regarding python and the pyalluvial package. I'm hoping to combine stacked bars and a corresponding alluvial in the same figure.

Using below, I have three unique groups, which is outlined in Group. I want to display the proportion of each Group for each unique Point. I have the data formatted this way as I need three separate stacked bar charts for each Point.

So overall (Ove) highlight the overall proportion taken from all three Points. Group 1 makes up 70%, Group 2 makes up 20%, Group 3 makes up 10%. But the proportion of each group changes at different intervals Points. I'm hoping to show this like a standard stacked bar chart, but add the alluvial over the top.

import pandas as pd
import pyalluvial.alluvial as alluvial 

df = pd.DataFrame({
    'Group': [1, 2, 3],
    'Ove': [0.7, 0.2, 0.1],
    'Point 1': [0.8, 0.1, 0.1],
    'Point 2': [0.6, 0.2, 0.2],
    'Point 3': [0.7, 0.3, 0.0],
    })

ax = alluvial.plot(
   df = df, 
   xaxis_names = ['Group','Point 1','Point 2', 'Point 3'], 
   y_name = 'Ove', 
   alluvium = 'Group',
)

Output shows the overall group proportion (1st bar) being correct. But the following stacked bars with the proportions.

If I transform the df and put the Points as a single column, then I don't get 3 separate bars.

enter image description here



from stacked chart combine with alluvial plot - python

No comments:

Post a Comment