0

I ploted streamlines using the u and v. How do i determine whether divergence or convergence was occurring and plot those shapes in same figure with matplotlib?

streamline test, red is divergence and blue is convergence.

enter image description here

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
ziming li
  • 11
  • 2

1 Answers1

1

You can colour streamlines in any way you want, so get whatever form of divergence you want and use that,

import numpy as np
import matplotlib.pyplot as plt

Y, X = np.mgrid[-3:3:100j, -3:3:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
divUV = reduce(np.add,np.gradient(U)) + reduce(np.add,np.gradient(V))

fig, ax = plt.subplots()
strm = ax.streamplot(X, Y, U, V, color=divUV, cmap=plt.cm.RdBu)
fig.colorbar(strm.lines)

plt.show()

Not sure the divergence looks right here but you get the idea. Alternatively, you could overlay a colormesh with transparency,

cm = ax.pcolormesh(X, Y, divU, cmap=plt.cm.RdBu, alpha=0.4)
fig.colorbar(cm)
Community
  • 1
  • 1
Ed Smith
  • 12,716
  • 2
  • 43
  • 55
  • yeah, great. This is a good alternative, but the divergence does not looks perfect. Probably shouldn't ask such a question here, the most important thing is to understand how to calculate the divergence and convergence in meteological. Thanks a lot. – ziming li Jul 14 '16 at 07:10