Text getting out of figsize plot.bar

You can try ax.set_ylim(..) just after plot.bar command, which will help you to customise the minimum and maximum limits of the y-axis. For example,:

ax = dados["NU_IDADE"].value_counts().sort_index().plot.bar(figsize=(25, 10))

for p in ax.patches:
  percent_label_text = (p.get_height() / len(dados)) * 100
  ax.annotate(f'{str(round(percent_label_text, 2 if percent_label_text >= 0.01 else 3))}%', (p.get_x(), p.get_height()), rotation='vertical', xytext=(2, 5), textcoords="offset points")

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top