def normvectorfield(xs,ys,fs,**kw):
"""
plot normalized vector field
kwargs
======
- length is a desired length of the lines (default: 1)
- the rest of kwards are passed to plot
"""
length = kw.pop('length') if 'length' in kw else 1
x, y = np.meshgrid(xs, ys)
# calculate vector field
vx,vy = fs(x,y)
# plot vecor field
norm = length /np.sqrt(vx**2+vy**2)
plt.quiver(x, y, vx * norm, vy * norm, angles='xy',**kw)
评论列表
文章目录