Skip to content

Instantly share code, notes, and snippets.

@FBosler
Last active August 31, 2019 14:14
Show Gist options
  • Save FBosler/7e2d277038139933aefc454c61e4906c to your computer and use it in GitHub Desktop.
Save FBosler/7e2d277038139933aefc454c61e4906c to your computer and use it in GitHub Desktop.
def plot_bars(data,x_col,y_col):
data = data.reset_index()
sns.set(
font_scale=1.5,
style="whitegrid",
rc={'figure.figsize':(20,7)}
)
g = sns.barplot(x=x_col, y=y_col, data=data, color='royalblue')
for p in g.patches:
g.annotate(
format(p.get_height(), '.2%'),
(p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center',
va = 'center',
xytext = (0, 10),
textcoords = 'offset points'
)
vals = g.get_yticks()
g.set_yticklabels(['{:,.0f}%'.format(x*100) for x in vals])
sns.despine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment