I’m using a loop to generate vector fields on a basemap as such:
for i in range(365):
barbs = m.quiver(x, y, u[i, :], v[i, :], scale = 100)
plt.draw()
barbs.remove()
The program takes drastically more memory with every loop. Is there a way to get around this? Such as deleting barbs entirely at the end of each loop?
If you only need to reset the (u,v) components you can use
barb.set_UVC(newU,newV,newC)inside the loop.Also see Python: copy basemap or remove data from figure, Visualization of 3D-numpy-array frame by frame,
If you are trying to create an animation, look in to the
animationmodule of matplotlib, it takes care of a lot of the details for you.