Last active
August 27, 2019 06:47
-
-
Save MosaabMuhammed/2a700d5908d081aa09f0386cb905fc53 to your computer and use it in GitHub Desktop.
Show annotation on the barplot in seaborn library (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ****************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