This part of the mission explans how to use a for loop to creat multiple plots. There is this code there:
fig = plt.figure(figsize=(12,5))
for i in range(2): ax = fig.add_subplot(2,1,i+1) start_index = i*12 end_index = (i+1)*12 subset = unrate[start_index:end_index] ax.plot(subset['DATE'], subset['VALUE']) plt.show()
Since each loop is assigning the subplot the same variable (ax), I would expect that it would keep only the subplot assigned in the second and last loop, since the plt.show() is outside the loop:
for i in range(2): ax = fig.add_subplot(2,1,2) start_index = 1*12 end_index = (1+1)*12 subset = unrate[12:24] ax.plot(subset['DATE'], subset['VALUE']) plt.show()
My question is: why the plt.show() shows the both plots and not just the second one, since it is the value assigned to the ax variable when the for loop ends?