文本超出Figsizeplot.bar

我想修复从我的plot.bar()中得到的str数字而不改变figsize。这个有可能 ?


我的代码:


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")

我的情节吧:

https://img1.sycdn.imooc.com/658a77dc0001a85815090600.jpg

守着星空守着你
浏览 40回答 1
1回答

慕的地10843

ax.set_ylim(..) 您可以在命令之后尝试plot.bar,这将帮助您自定义 y 轴的最小和最大限制。例如,:ax = dados["NU_IDADE"].value_counts().sort_index().plot.bar(figsize=(25, 10))ax.set_ylim([0,22500])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")
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python