Skip to content

Instantly share code, notes, and snippets.

@MosaabMuhammed
Last active August 27, 2019 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MosaabMuhammed/2a700d5908d081aa09f0386cb905fc53 to your computer and use it in GitHub Desktop.
Save MosaabMuhammed/2a700d5908d081aa09f0386cb905fc53 to your computer and use it in GitHub Desktop.
Show annotation on the barplot in seaborn library (Python)
# ****************SHOW ANNOTATIONS in plt plot**********
def show_annotation(colName):
# Add Anootations
n_points = df.shape[0]
col_count = df[colName].value_counts()
locs, labels = plt.xticks() # Get the current tick locations and labels
# Loop for through each pair of locations and labels.
for loc, label in zip(locs, labels):
count = col_count[int(label.get_text())]
text = '{:.2f}%'.format(100*count/n_points)
plt.text(loc, count-50, text, ha='center', color='darkblue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment