Вы можете проверить виньетку для аннотации в matplotlib. Чтобы разместить аннотацию поверх столбцов, вы можете рассчитать максимальную высоту каждой записи по оси x и использовать аннотацию (по умолчанию textcoords='data'
):
data2 = pd.DataFrame({'Date': {0: '2020-06-01',
1: '2020-06-02',
2: '2020-06-03',
3: '2020-06-04',
4: '2020-06-08'},
'Started': {0: 1, 1: 1, 2: 3, 3: 2, 4: 2},
'Ended': {0: 0, 1: 0, 2: 2, 3: 0, 4: 1},
'conversion': {0: 0.0, 1: 0.0, 2: 0.67, 3: 0.0, 4: 0.5}})
fig, ax = plt.subplots(figsize=(8,3))
data2.set_index('Date').plot.bar(ax=ax)
hts = data2.iloc[:,1:].apply(max,axis=1) - 0.05
for i in range(len(hts)):
ax.text(i,hts[i],data2['conversion'][i])
To annotate under the x-axis, you do something similar, just that you need to transform the x-axis:
fig, ax = plt.subplots(figsize=(8,3))
data2.set_index('Date').plot.bar(ax=ax)
for i in range(len(hts)):
ax.annotate(data2['conversion'][i],xy=(i,-0.6),
xycoords=ax.get_xaxis_transform(),color="blue")
введите описание изображения здесь