4

I'd like to draw and animate some particles with matplotlib. Each point has a position and velocity. I am able to draw single frames using matplotlib quiver.

But how can I update the quiver data for each frame? (I am using the matplotlib animation class.) I read about the (undocumented?) quiver.set_UVC(), but that seems to update only the direction, not position. Is there any other way to do this?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
M-V
  • 5,167
  • 7
  • 52
  • 55
  • [possible duplicate](http://stackoverflow.com/questions/12015427/update-a-figure-made-with-imshow-contour-and-quiver/12253893#12253893) – ali_m Jul 20 '13 at 11:44
  • 5
    Not duplicate, @ali_m, as set_UVC() does not allow you to update positions, which is what I was asking about. – M-V Jul 20 '13 at 14:43

1 Answers1

9

You can do this via the Collections level method set_offsets (doc).

X, Y = np.meshgrid(linspace(0, 100), linspace(0, 100))
q = plt.quiver(X, Y , rand(100, 100), rand(100, 100))
plt.draw()
plt.pause(2)
q.set_offsets(q.get_offsets() * np.array([1, .5]))
plt.draw()
tacaswell
  • 84,579
  • 22
  • 210
  • 199