0

I would like to separate my labels on the x-axis according to their category (female/male).

I have the following code:

import matplotlib.pyplot as plt
import pandas as pd

if __name__=='__main__':
    data = {
        'Ava': 30, 
        'Charlotte': 32,
        'Sophia': 41, 
        'Mark': 33,
        'William': 50
    }

    data_df = pd.DataFrame(data, index=[0]).T
    data_df.plot(kind='bar', rot=0, edgecolor='black', legend=False)

    plt.title('Age')
    plt.savefig('ages.png')

It produces the following plot

I want to add lines to group x-axis labels according to gender.

FEMALE = ['Ava', 'Charlotte', 'Sophia']
MALE = ['Mark', 'William']

And obtaining something like this

How can I do it?

rrpp1045
  • 1
  • 2
  • See https://stackoverflow.com/a/66121322/13636407 and https://stackoverflow.com/a/51824748/13636407 – paime Dec 06 '22 at 15:33

0 Answers0