Skip to content

Instantly share code, notes, and snippets.

@satyabansahoo2000
Created November 30, 2020 09:01
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 satyabansahoo2000/8867c96f8ee4696a63f2bb698274e33d to your computer and use it in GitHub Desktop.
Save satyabansahoo2000/8867c96f8ee4696a63f2bb698274e33d to your computer and use it in GitHub Desktop.
Annotating in Plots
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("white")
plt.figure(figsize=(10,5))
g = sns.countplot(x="", y="", data=df)
for p in g.patches:
g.annotate(format(p.get_height(), '.2f'), (p.get_width()/2., p.get_height()),
ha='center', va='center', xytext=(0,9), textcoords = 'offset points',
fontsize=8, horizontalalignment='right')
plt.show()
# "textcoords" helped in placing the annotations next to their respective bars
# Setting the "horizontalalignment" to "right" gets them towards the end of the bars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment