我想修復從我的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")我的情節吧:
1 回答

慕的地10843
TA貢獻1785條經驗 獲得超8個贊
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")
添加回答
舉報
0/150
提交
取消