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?