Skip to content

Instantly share code, notes, and snippets.

@will-gao42
Created January 5, 2022 00:38
Show Gist options
  • Save will-gao42/73ad92f1971397e59526b6a9ba7b1ccc to your computer and use it in GitHub Desktop.
Save will-gao42/73ad92f1971397e59526b6a9ba7b1ccc to your computer and use it in GitHub Desktop.
Display Values on Bars
def show_values_barplot(axs, space):
def _show_on_plot(ax):
for p in ax.patches:
_x = p.get_x() + p.get_width() + float(space)
_y = p.get_y() + p.get_height()
value = round(float(p.get_width()), 2)
ax.text(_x, _y, value, ha="left")
if isinstance(axs, np.ndarray):
for idx, ax in np.ndenumerate(axs):
_show_on_plot(ax)
else:
_show_on_plot(axs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment