4

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?

pter
  • 611
  • 2
  • 9
  • 16
  • Why do you draw them and then remove them? One way to speed up plots is to build them first, and then call draw at the end, with interactive mode set to off, by calling ioff(). You're example is far from this, but because it's incomplete, it's hard to guess what you want. – tom10 Aug 29 '12 at 04:02

1 Answers1

4

If you only need to reset the (u,v) components you can use barb.set_UVC(newU,newV,newC) inside the loop.

barbs = m.quiver(x, y, u[0, :], v[0, :], scale = 100)
for i in range(365):
     barbs.set_UVC(u[i,:],v[i,:])
     #save the figure or something

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 animation module of matplotlib, it takes care of a lot of the details for you.

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199