matplotlib quiver:Invalid RGBA 参数
matplotlib quiver:Invalid RGBA argument
这段代码是我写的
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
%matplotlib inline
%pylab
from scipy.ndimage import gaussian_filter
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
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)
# cmap = plt.cm.get_cmap("inferno", 7).colors
# colors = list((mcolors.to_hex(x) for x in cmap))
plt.quiver(U[::7, ::7], V[::7, ::7], C=M, cmap='inferno', scale=0.4, scale_units = 'xy', headlength = 7)
#plt.axis('off')
plt.gca().invert_yaxis()
plt.savefig('/home/roberto/workspace/TEST/OUTPUT/CORRECTIONCLEAN/TEST0.png')
matplotlib.pyplot.clf()
EDIT 省略了一个括号
编辑 2 将生成器更改为列表
编辑 3 试图将颜色设置为箭头的大小
这段代码是我写的
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
%matplotlib inline
%pylab
from scipy.ndimage import gaussian_filter
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
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)
# cmap = plt.cm.get_cmap("inferno", 7).colors
# colors = list((mcolors.to_hex(x) for x in cmap))
plt.quiver(U[::7, ::7], V[::7, ::7], C=M, cmap='inferno', scale=0.4, scale_units = 'xy', headlength = 7)
#plt.axis('off')
plt.gca().invert_yaxis()
plt.savefig('/home/roberto/workspace/TEST/OUTPUT/CORRECTIONCLEAN/TEST0.png')
matplotlib.pyplot.clf()
EDIT 省略了一个括号 编辑 2 将生成器更改为列表 编辑 3 试图将颜色设置为箭头的大小