Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: Superimpose multiple 2d quiver plots over time

I have some vector fields that vary in 2d space and over time. Conventionally, one could visualize the evolution of the vector fields as a 2D movie where the magnitudes and angles of all quivers change in time.

To be explicit, currently I have U and V each with shape (x,y,t) where dims 0 and 1 are spatial coordinates and t is a particular time slice. I can visualize the vector field for a specific time as: matplotlib.pyplot.quiver(U[:,:,i], V[:,:,i]) where i is a particular time index. Currently I can visualize this evolution in a for-loop iterating over all i.

However, I would like to visualize each of the quiver plots in time on a single 2 dimensional plot. To do this I want to assign each index i as a different color from a given colormap. Therefore all quivers from a particular time point appear as a single color.

Can anybody suggest an approach?

Thank you in advance!

like image 879
Ankit Avatar asked Jan 24 '26 22:01

Ankit


1 Answers

You could do something along the lines of:

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

U = np.random.rand(10, 10, 10) - 0.5
V = np.random.rand(10, 10, 10) - 0.5
cmap = plt.cm.jet
time_samples = U.shape[-1]
for t in xrange(time_samples):
    plt.quiver(U[..., t], V[..., t], color=cmap(j/time_samples))
plt.show()

enter image description here

like image 77
Jaime Avatar answered Jan 27 '26 11:01

Jaime



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!