0

I have the following dataframe that counts the number of managers and non managers per sex in each Business Unit (it is a multiindex that sums the value of Male and Female that are manager or not in each Business Unit). It may happen, as you can see, that a Business Unit has only Non Manager or Manager as employees:

                                       Female  Male
Business Unit Professional Category              
South         Non Manager                37    45
West          Non Manager                31    37
East          Manager                    14    15
              Non Manager               342   412
Noth          Manager                     5     5
              Non Manager               457   550
Center        Non Manager                44    53

I wanted to create a stacked bar chart where in the x-axis I have the Professional Category (one bar for Manager and one separete bar for Non Manager) and in each of those bars the stacked amount of Male and Female. But I would need to repeat this same stacked bar graph for each of the regions: South, West, East, Noth, Center.

What would be the most elegant wat to display this information in matplotlib/seaborn?

Thank you so much in advance!

1 Answer 1

1

IIUC, try:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 5, figsize=(20, 8))
iax = iter(ax.flatten())
for n, g in df.groupby('Business Unit'):
    g.loc[n, :].plot.bar(ax=next(iax), title=f'{n}', stacked=True)

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that is exactly what I needed, thanks! Do you happen to know how could I display the % of the total from Male and Female inside the stacked bar by any chance? Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.