Created
January 5, 2022 00:38
-
-
Save will-gao42/73ad92f1971397e59526b6a9ba7b1ccc to your computer and use it in GitHub Desktop.
Display Values on Bars
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
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