Home > Back-end >  Add labels as percentages instead of counts on a grouped bar graph in seaborn
Add labels as percentages instead of counts on a grouped bar graph in seaborn

Time:01-16

I have a categorical dataset which I am plotting a bar graph using seaborn. However I am unable to add labels on top of bars in percentage value. Here is how the dataset looks like:

import pandas as pd

#create DataFrame
df = pd.DataFrame({'Day': ['Mon', 'Tue', 'Wed', 'Thur', 'Fri',
                           'Mon', 'Tue', 'Wed', 'Thur', 'Fri'],
                   'Customers': [44, 46, 49, 59, 54,
                                 33, 46, 50, 49, 60],
                   'Time': ['M', 'M', 'M', 'M', 'M',
                            'E', 'E', 'E', 'E', 'E']})

#view DataFrame
df

This is the code for plotting grouped bar graph:

import matplotlib.pyplot as plt
import seaborn as sns

#set seaborn plotting aesthetics
sns.set(style='white')

#create grouped bar chart
sns.barplot(x='Day', y='Customers', hue='Time', data=df) 

Now I would like to add labels on top of bars but in percentage value. Kindly help

CodePudding user response:

Use

  •  Tags:  
  • Related