这可能会奏效:
plt.quiver(x, y, u, v, np.arctan2(v, u), angles='xy', scale_units='xy', scale=1, pivot='mid',color='g')
注意plt.quiver 的第五个参数是颜色。
UPD。如果你想控制颜色,你必须使用colormaps。以下是几个例子:
使用带有colors参数的颜色图:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import Normalize
%matplotlib inline
ph = np.linspace(0, 2*np.pi, 13)
x = np.cos(ph)
y = np.sin(ph)
u = np.cos(ph)
v = np.sin(ph)
colors = arctan2(u, v)
norm = Normalize()
norm.autoscale(colors)
# we need to normalize our colors array to match it colormap domain
# which is [0, 1]
colormap = cm.inferno
# pick your colormap here, refer to
# http://matplotlib.org/examples/color/colormaps_reference.html
# and
# http://matplotlib.org/users/colormaps.html
# for details
plt.figure(figsize=(6, 6))
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.quiver(x, y, u, v, color=colormap(norm(colors)), angles='xy',
scale_units='xy', scale=1, pivot='mid')
您也可以像我的第一个示例中那样坚持使用第五个参数(与 colors 相比,它的工作方式略有不同)并更改默认颜色图以控制颜色。
plt.rcParams['image.cmap'] = 'Paired'
plt.figure(figsize=(6, 6))
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.quiver(x, y, u, v, np.arctan2(v, u), angles='xy', scale_units='xy', scale=1, pivot='mid')
您还可以创建自己的颜色图,参见例如here.