Pyplot Multiple Plot

How does the code line legend know to take the values from label??

fig = plt.figure(figsize=(10,6))
colors = [‘red’, ‘blue’, ‘green’, ‘orange’, ‘black’]

for i in range(5):
start_index = i*12
end_index = (i+1)*12
subset = unrate[start_index:end_index]
label = str(1948 + i)
plt.plot(subset[‘MONTH’], subset[‘VALUE’], c=colors[i], label=label)
plt.legend(loc=‘upper left’)


hey @ANDI

I have not done deep dive when it comes to Matplotlib library. I have got this from their official documentation about legends.

In simple terms, the method legend() automatically takes the values of label.

link for the official doc