我一直在尝试运行以下代码: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条经验 获得超12个赞
使用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
提交
取消