Skip to content

Instantly share code, notes, and snippets.

@austinmcconnell
Created October 17, 2019 15:50
Show Gist options
  • Save austinmcconnell/353ce39fedea5d8e5a9ab9dcc22c3742 to your computer and use it in GitHub Desktop.
Save austinmcconnell/353ce39fedea5d8e5a9ab9dcc22c3742 to your computer and use it in GitHub Desktop.
def label_datapoints(axes, percent=False):
if percent:
precision = 2
extra = '%'
else:
precision = 0
extra = ''
for patch in axes.patches:
axes.text(x=patch.get_x() + patch.get_width() / 2.,
y=patch.get_height(),
s='{:.{prec}f}{extra}'.format(float(patch.get_height()),
prec=precision,
extra=extra),
fontsize=14,
color='black',
ha='center',
va='bottom')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment