Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to update quiver position coordinates in an animation?

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?

like image 529
M-V Avatar asked Oct 28 '25 09:10

M-V


1 Answers

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()
like image 114
tacaswell Avatar answered Oct 30 '25 08:10

tacaswell