【问题标题】:matplotlib streamline with the area of divergence and convergencematplotlib 流线型与发散和收敛区域
【发布时间】:2016-07-13 16:18:32
【问题描述】:

我使用 u 和 v 绘制流线。我如何确定是否发生了分歧或收敛,并使用 matplotlib 在同一图中绘制这些形状?

streamline test, red is divergence and blue is convergence.

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    你可以用任何你想要的方式为流线着色,所以得到你想要的任何形式的divergence并使用它,

    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()
    

    不确定分歧是否在这里,但你明白了。或者,您可以使用透明度覆盖颜色网格,

    cm = ax.pcolormesh(X, Y, divU, cmap=plt.cm.RdBu, alpha=0.4)
    fig.colorbar(cm)
    

    【讨论】:

    • 是的,太好了。这是一个不错的选择,但分歧看起来并不完美。可能不应该在这里问这样的问题,最重要的是要了解如何计算气象中的发散和收敛。非常感谢。
    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2019-09-22
    • 2017-05-21
    • 2013-08-01
    • 2021-09-24
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多