我写了这段代码
from scipy.ndimage import gaussian_filter
U = gaussian_filter(optflow[1][:,:,0], sigma = 10)
V = gaussian_filter(optflow[1][:,:,1], sigma = 10)
U[abs(U) < 0.5] = 0
V[abs(V) < 0.5] = 0
plt.quiver(U[::7, ::7], V[::7, ::7], scale=0.4, scale_units = 'xy', headlength = 7)
#plt.axis('off')
plt.gca().invert_yaxis()
plt.savefig('/home/RR/TEST0.png')
matplotlib.pyplot.clf()
绘制这种形式的矢量场:
我的问题是:如何根据箭头的模块更改箭头的颜色
我试过这个:
%matplotlib inline
%pylab
from scipy.ndimage import gaussian_filter
U = gaussian_filter(optflow[1][:,:,0], sigma = 10)
V = gaussian_filter(optflow[1][:,:,1], sigma = 10)
U[abs(U) < 0.5] = 0
V[abs(V) < 0.5] = 0
M = np.sqrt(U*U+V*V)
plt.quiver(U[::7, ::7], V[::7, ::7], color = cm.inferno(M), scale=0.4, scale_units = 'xy', headlength = 7)
#plt.axis('off')
plt.gca().invert_yaxis()
plt.savefig('/home/RR7g.png')
matplotlib.pyplot.clf()
但是出现了以下错误
Invalid RGBA argument
编辑省略的括号 将2个更改的生成器编辑为列表 编辑3尝试将颜色设置为箭头的大小
相关问题 更多 >
编程相关推荐