Ankit
Ankit

Reputation: 23

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!

Upvotes: 2

Views: 3141

Answers (1)

Jaime
Jaime

Reputation: 67467

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

Upvotes: 9

Related Questions