'How to I add line annotations to an animated line graph with multiple lines?

I would like to add annotations to each line on my animated matplotlib line graph. I would like to annotation to display the bird species (e.g. Wetland, Seabird etc.). Can anyone help? I've tried using existing solutions but don't know how to incorporate them into my code. Thank you!

from matplotlib import animation
from matplotlib.animation import FuncAnimation
from itertools import count
%matplotlib qt

l1 = df["all_species"]
l2 = df["farmland"]
l3 = df["woodland"]
l4 = df["wetland"]
l5 = df["seabirds"]
l6 = df["winteringwater"]
l7 = df["wildfowl"]
l8 = df["wader"]
xval = df["Year"]
x1,y1,y2,y3,y4,y5,y6,y7,y8 = [], [], [], [], [], [], [], [], []

fig, axes = plt.subplots(nrows = 1, ncols = 1, figsize = (15,7.5))
axes.set_ylim(0, 250)
axes.set_xlim(1970, 2020)
plt.style.use("ggplot")
plt.title('The index chart visualises the change in the UK wild bird population based on 1970 
as an index year. The index is published by the Birtish Trust for' 
      "\n" 'Ornithology (BTO) and the Royal Society for the Protection of Birds (RSPB).', 
fontsize=10, loc="left")
plt.suptitle('Population of wild birds: 1970 to 2019',fontsize=16, y=0.99, fontweight="bold", 
horizontalalignment='right')
axes.set_xlabel('Year', fontsize=10)
axes.set_ylabel('Index value 1970=100', fontsize=10)
plt.axhline(100, linestyle='--', linewidth=1, alpha=0.7, color='#679186')

def animate(i):

 x1.append(1970+i)
 y1.append((l1[i]))
 y2.append((l2[i]))
 y3.append((l3[i]))
 y4.append((l4[i]))
 y5.append((l5[i]))
 y6.append((l6[i]))
 y7.append((l7[i]))
 y8.append((l8[i]))

 axes.plot(x1,y1, color="#454d66", linewidth=2, label='All species')    
 axes.plot(x1,y2, color="#309975", linewidth=2, label='Farmland')
 axes.plot(x1,y3, color="#58b368", linewidth=2, label='Woodland')
 axes.plot(x1,y4, color="#dad873", linewidth=2, label='Wetland')
 axes.plot(x1,y5, color="#ffca7a", linewidth=2, label='Seabirds')
 axes.plot(x1,y6, color="#2c698d", linewidth=2, label='Wintering Water')
 axes.plot(x1,y7, color="#e3f6f5", linewidth=2, label='Wildfowl')    
 axes.plot(x1,y8, color="#bae8e8", linewidth=2, label='Wader')
 ax.legend()


anim = FuncAnimation(fig, animate, interval=1)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source