I believe it is because the axes object is being garbage collected when it goes out of scope at the end of the function.