首页 > 解决方案 > Matplotlib 流图不同颜色

问题描述

我打算用不同的颜色制作一个流线图,用二维数组表示不同点的强度。u,v 代表不同点的风分量。

代码:

x = np.linspace(71.679886,100.43091,299) ##longitude
y = np.linspace(10.64794,31.228256,231)  ##latitude
level = [0,5]
for t in level:  ##t is level in output
    U = u[t,:,:]
    V = v[t,:,:]
    f = X[t,:,:]
    SPD = sqrt(u**2+v**2)
    print(SPD)
    pyplot.streamplot(x,y,u,v,density=5,arrowsize=1,integration_direction='forward',color=SPD,cmap="autumn",linewidth=2)
    pyplot.show()

输出应与此类似: 在此处输入图像描述

链接显示,可以通过使用 指定 2D 数组来制作此类图color,但我收到错误:ValueError: RGBA sequence should have length 3 or 4如果我使用 2D 数组,则color=SPD. 请帮忙。

标签: pythonpython-3.xmatplotlib

解决方案


推荐阅读