Skip to content

Instantly share code, notes, and snippets.

@robintux
Created July 21, 2022 17:47
Show Gist options
  • Save robintux/8f012ec6af74fb0ca3118333659bf0d4 to your computer and use it in GitHub Desktop.
Save robintux/8f012ec6af74fb0ca3118333659bf0d4 to your computer and use it in GitHub Desktop.
Funcion para mostrar la altura de las barras en un sns.barplot
def show_values(axs, orient="v", space=.01):
def _single(ax):
if orient == "v":
for p in ax.patches:
_x = p.get_x() + p.get_width() / 2
_y = p.get_y() + p.get_height() + (p.get_height()*0.01)
value = '{:.1f}'.format(p.get_height())
ax.text(_x, _y, value, ha="center")
elif orient == "h":
for p in ax.patches:
_x = p.get_x() + p.get_width() + float(space)
_y = p.get_y() + p.get_height() - (p.get_height()*0.5)
value = '{:.1f}'.format(p.get_width())
ax.text(_x, _y, value, ha="left")
if isinstance(axs, np.ndarray):
for idx, ax in np.ndenumerate(axs):
_single(ax)
else:
_single(axs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment