0

Consider that i have the following Dataframe. The last column CumSumPerGroup, represent the sum per group of unique combination of Status_Group + Department.

Status_Group Department Status Variable CumSumPerGroup
A DeptA Accepted 168 168
A DeptA Approved 68 236
A DeptA New 153 389
A DeptA Pending Approval 51 440
A DeptA WIP 11 451
B DeptA Closed 127 127
B DeptA Completed 3 130
B DeptA Rejected 20 150
A DeptB Accepted 45 45
A DeptB Approved 32 77
A DeptB New 7 84
B DeptB Closed 71 71
B DeptB Completed 1 72
B DeptB Unsolved 1 73
A DeptC Approved 3 3

What i am looking to do have Department values on X-axis, Grouped by Status_Group and Stacked by Status. see figure: What i am trying to achieve

Solution Attempt:

Following the solution that was provided here: text,I modified the code as follows:

fig,ax=plt.subplots(figsize=(11,8))    
for i, g in enumerate(df1.groupby("Status")):
    ax = sns.barplot(data=g[1],
                     x= "Department",
                     y="CumSumPerGroup",
                     hue="Status_Group",
                     color=colors[i],
                     zorder=-i, # so first bars stay on top
                     edgecolor="k")
    for i in ax.containers:
        ax.bar_label(i,)

My output seem to keep only the first Department. Image obtained from code.

Any help is highly appreciated

Mkj256
  • 1
  • 2

0 Answers0