How to add counts to Python Matplotlib Pandas Dataframe Bar Charts

Bar chart annotated with the counts
  1. Create the chart and save to ax
  2. Use the following code snippet to annotate with the counts:
for p in ax.patches:
ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Digest

Digest

58 Followers

One Digest At a Time. I value your time! #datascience #dataanalyst #datascientist #probability #statistics #ML #AI #savetime #digest