Created
January 9, 2019 11:14
-
-
Save Den1al/5b65c88c791a700dbf4482c41d253727 to your computer and use it in GitHub Desktop.
Pandas plot bar/barh annotation script
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
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