我一直在嘗試運行以下代碼:df = alc_gasolina[(alc_gasolina['ANO'] == 2009) & (alc_gasolina['MêS'] == 5)]ax = sns.barplot(y="PRE?O MéDIO REVENDA",x="DIA", hue="PRODUTO", data=df )ax.set(ylim=(1.4,2.6))for index, row in df.iterrows(): ax.text(row.DIA,row['PRE?O MéDIO REVENDA'], round(row['PRE?O MéDIO REVENDA'],2), color='black', ha="center")結果如下圖:(文本未對齊。)誰能幫忙?
1 回答

紅顏莎娜
TA貢獻1842條經驗 獲得超13個贊
使用ax.patches你可以實現它。
df:
a b c d
a1 66 92 98 17
a2 83 57 86 97
a3 96 47 73 32
ax = df.T.plot(width=0.8, kind='bar',y=df.columns,figsize=(10,5))
for p in ax.patches:
ax.annotate(str(round(p.get_height(),2)), (p.get_x() * 1.005, p.get_height() * 1.005),color='green')
ax.axes.get_yaxis().set_ticks([])
添加回答
舉報
0/150
提交
取消