Skip to content

Instantly share code, notes, and snippets.

@Den1al
Created January 9, 2019 11:14
Show Gist options
  • Save Den1al/5b65c88c791a700dbf4482c41d253727 to your computer and use it in GitHub Desktop.
Save Den1al/5b65c88c791a700dbf4482c41d253727 to your computer and use it in GitHub Desktop.
Pandas plot bar/barh annotation script
import pandas as pd
from matplotlib import pyplot as plt
plt.figure(figsize=(10,5))
ax = df.column1.sort_values(ascending=False).head(10).plot.barh()
ax.set_title("My Awesome Title", fontsize=12)
for patch in ax.patches:
ax.text(
patch.get_width() + 0.3,
patch.get_y() + 0.38,
" {:,}".format(patch.get_width()),
fontsize=10,
color='dimgrey'
)
ax.invert_yaxis()
# plt.savefig('tls.png', bbox_inches = "tight")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment